指定基于类实例的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
//..........
}
}
答案 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);