JAXB Class Instance Listener

391 Views Asked by At

What is the way to specify Class Instance based JAXB Listener (as in Entity Bean) like : afterUnmarshall , beforeMarshall but on every class instance based (by implementing any interface or by annotation).

@XmlRootElement(name = "Person")                            // Edited
    public class Person {
        protected String name; //setter getter also implemented

        void beforeMarshall(){
         //..........
        }

        void afterUnmarshall (){  // by implementing any interface or by annotation
         //..........
        }
 } 
1

There are 1 best solutions below

4
On BEST ANSWER

JAXB will match the following method signatures for those events:

   // This method is called immediately after the object is created and before the unmarshalling of this 
   // object begins. The callback provides an opportunity to initialize JavaBean properties prior to unmarshalling.
   void beforeUnmarshal(Unmarshaller, Object parent);

   //This method is called after all the properties (except IDREF) are unmarshalled for this object, 
   //but before this object is set to the parent object.
   void afterUnmarshal(Unmarshaller, Object parent);