我正在嘗試編寫JAXB XMLAdapter,以便xs:dateTime字段不會創建爲XMLGregorianCalendar
,而是創建爲joda DateTime
。從Calendar到Joda的JAXB適配器DateTime
但它並不像預期的那樣工作,特別是自動生成的適配器在類型間自動生成的某種程度上完全錯誤(wsdl2java)。但爲什麼?
<jaxb:globalBindings>
<jaxb:javaType name="org.joda.time.DateTime" xmlType="xsd:dateTime"
parseMethod="my.DateTimeAdapter.unmarshal"
printMethod="my.DateTimeAdapter.marshal" />
</jaxb:globalBindings>
public class DateTimeAdapter extends XmlAdapter<DateTime, Calendar>{
@Override
public Calendar unmarshal(DateTime date) throws Exception {
return date.toGregorianCalendar();
}
@Override
public DateTime marshal(Calendar date) throws Exception {
return new DateTime(date);
}
}
結果(自動生成):
public class Adapter1
extends XmlAdapter<String, Date>
{
public Date unmarshal(String value) {
return (javax.xml.bind.DatatypeConverter.parseDateTime(value));
}
public String marshal(Date value) {
if (value == null) {
return null;
}
return (javax.xml.bind.DatatypeConverter.printDateTime(value));
}
}
爲什麼結果定義的String, Date
,而不是我的類型的適配器?