我已经编写了一个适配器来处理JodaTime中的句点https://www.joda.org/joda-time/apidocs/org/joda/time/Period.html与JAXB的序列化,正如它在http://blog.bdoughan.com/2011/05/jaxb-and-joda-time-dates-and-times.html中所说的那样,但它不起作用。
public class PeriodAdapter extends XmlAdapter<String, Period>{
@Override
public Period unmarshal(String p) throws Exception {
return new Period(p);
}
@Override
public String marshal(Period p) throws Exception {
return p.toString();
}
}
然后在我的课程中我需要使用适配器我使用注释
public class ActiveHistorySettings {
private Period maximumPeriod;
@Min(0)
private int maximumAccesses;
@XmlJavaTypeAdapter(PeriodAdapter.class)
public Period getMaximumPeriod() {
return this.maximumPeriod;
}
如果我调试应用程序,在尝试解组我的xml之前没有使用适配器......
这是堆栈跟踪
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
org.joda.time.base.BasePeriod does not have a no-arg default constructor.
this problem is related to the following location:
at org.joda.time.base.BasePeriod
at org.joda.time.Period
答案 0 :(得分:3)
问题是解决的。我在eclipse中的构建路径出了问题。实际上,我没有使用JAXB库。现在我正在使用jaxb 2.2.4 http://jaxb.java.net/,当我调试应用程序时,我的适配器已被使用:D