Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.sql.Timestamp does not have a no-arg default constructor.
this problem is related to the following location:
at java.sql.Timestamp
at public java.sql.Timestamp com.yazuo.api.service.account.vo.MerchantProductVo.getBeginTime()
at com.yazuo.api.service.account.vo.MerchantProductVo
使用cxf 框架 构造webservice 接口的使用, 如果返回对象中定义了 java.sql.Timestamp 会出现以上异常, 原因 , cxf 解析返回对象的时候需要使用无参构造函数, java中本来默认每一个类都有一个无参构造函数, 但是我们发现
有这连个构造函数后, java 的默认无参构造函数实效, 到时cxf 无法解析到这个类,出现以上错误
解决办法:
1、 在接口中不使用 java.sql.Timestamp
2、使用XmlAdapter 来覆盖绕过
其中2的使用方式:
import java.sql.Timestamp;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class TimestampAdapter extends XmlAdapter<Date, Timestamp> {
public Date marshal(Timestamp v) {
return new Date(v.getTime());
}
public Timestamp unmarshal(Date v) {
return new Timestamp(
v.getTime());
}
}
}
@XmlJavaTypeAdapter(value = TimestampAdapter.class, type = Timestamp.class)
public java.sql.Timestamp getBeginTime() {
return beginTime;
}
public void setBeginTime(java.sql.Timestamp beginTime) {
this.beginTime = beginTime;
}
@XmlJavaTypeAdapter(value = TimestampAdapter.class, type = Timestamp.class)
public java.sql.Timestamp getEndTime() {
return endTime;
}