使用Jaxb序列化JodaTime期间(BasePeriod没有默认构造函数)
我已经编写了一个适配器,用JAXB处理JodaTime中一个周期的序列化,如中所述,但它不起作用使用Jaxb序列化JodaTime期间(BasePeriod没有默认构造函数),jaxb,jodatime,Jaxb,Jodatime,我已经编写了一个适配器,用JAXB处理JodaTime中一个周期的序列化,如中所述,但它不起作用 public class PeriodAdapter extends XmlAdapter<String, Period>{ @Override public Period unmarshal(String p) throws Exception { return new Period(p); } @Override public String marshal(Period
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();
}
如果我调试应用程序,则在尝试解组xml之前,适配器未被使用
这是stacktrace
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
问题已经解决了。我在eclipse中的构建路径有问题。事实上,我没有使用JAXB库。现在我使用的是JAXB2.2.4,当我调试应用程序时,我使用的是适配器:D
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