我正在编译:
xjc -b temp.xml schema.xsd
这是 temp.xml 的一部分:
<jaxb:bindings node="//xs:element[@name='EventDate']">
<jaxb:property>
<jaxb:baseType>
<javaType name="java.util.Date"
parseMethod="com.mydomain.adapters.DateAdapter.parseDate"
printMethod="com.mydomain.adapters.DateAdapter.printDate"
/>
</jaxb:baseType>
</jaxb:property>
</jaxb:bindings>
这是 com.mydomain.adapters.DateAdapter 类的一部分:
private static final DateFormatter df = new DateFormatter("yyyy-MM-dd'T'HH:mm:ss z");
public static Date parseDate(String v) {
Date date = null;
try {
date = df.parse(v, Locale.getDefault());
} catch (ParseException e) {
throw new MyException("Could not parse date:" + v);
}
return date;
}
public static String printDate(Date v) {
return df.print(v, Locale.getDefault());
}