我有以下java类,并在payerPartyReference变量上放置了一个XmlJavaAdapter注释。我希望适配器PartyReferenceAdapter仅用于解组此变量,而不是任何其他具有相同类型的PartyReference的变量,无论是在此类还是其他类中。我怎样才能做到这一点?谢谢你的帮助!
public class InitialPayment extends PaymentBase
{
// Want PartyReferenceAdapter to be used here
@XmlJavaTypeAdapter(PartyReferenceAdapter.class)
protected PartyReference payerPartyReference;
//
// Dont want PartyReferenceAdapter to be used here
protected PartyReference receiverPartyReference;
//
protected AccountReference receiverAccountReference;
@XmlSchemaType(name = "date")
protected XMLGregorianCalendar adjustablePaymentDate;
@XmlSchemaType(name = "date")
protected XMLGregorianCalendar adjustedPaymentDate;
protected Money paymentAmount;
}
我的适配器定义如下:
public class PartyReferenceAdapter
extends XmlAdapter < Object, PartyReference > {
public PartyReference unmarshal(Object obj) throws Exception {
Element element = null;
if (obj instanceof Element) {
element = (Element)obj;
String reference_id = element.getAttribute("href");
PartyReference pr = new PartyReference();
pr.setHref(reference_id);
return pr;
}
public Object marshal(PartyReference arg0) throws Exception {
return null;
}
}
答案 0 :(得分:1)
字段/属性级别
如果在字段/属性上设置@XmlJavaTypeAdapter
,它将仅用于该属性。
类型级别
如果在类型上设置@XmlJavaTypeAdapter
,则它将用于对该类型的所有引用。
套餐级别
如果在包上设置@XmlJavaTypeAdapter
,那么它将用于该包中对该类型的所有引用: