I wrote an adapter to handle the serialization of the period https://www.joda.org/joda-time/apidocs/org/joda/time/Period.html in JodaTime with JAXB, as stated on http: // blog. bdoughan.com/2011/05/jaxb-and-joda-time-dates-and-times.html, but this does not work.
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(); }
}
and then in my class where I need to use an adapter, I use annotation
public class ActiveHistorySettings { private Period maximumPeriod; @Min(0) private int maximumAccesses; @XmlJavaTypeAdapter(PeriodAdapter.class) public Period getMaximumPeriod() { return this.maximumPeriod; }
If I debug the application, the adapter was not used before trying to parse my xml ...
this is a stack trace
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
source share