我已经写了一个适配器,因为在https://www.joda.org/joda-time/apidocs/org/joda/time/Period.html说来处理JodaTime一期http://blog.bdoughan.com/2011/05/jaxb-and-joda-time-dates-and-times.html与JAXB的序列,但它不工作。
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
这个问题是固定的。我有一个问题,在我的日食构建路径。事实上,我没有使用JAXB库。现在,我使用JAXB 2.2.4 http://jaxb.java.net/,当我调试应用程序我的适配器它被使用:d