JAXB类实例侦听器

时间:2013-12-02 20:40:13

标签: java xml-parsing jaxb jaxb2

指定基于类实例的JAXB侦听器(如在实体Bean中)的方法是什么:afterUnmarshall,beforeMarshall但是基于每个类实例(通过实现任何接口或注释)。

@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 个答案:

答案 0 :(得分:2)

JAXB将匹配以下方法签名:

   // 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);