我用Java编写我的web服务,并有一两件事,我卡住了。我想送的java.sql.Timestamp作为一个JSON响应,但得到了IllegalAnnotationException。我使用的球衣1.19以下是例外。
javax.ws.rs.WebApplicationException:
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 response.TransactionStatusResponse.command_receiving_datetime
at response.TransactionStatusResponse
at public java.util.List response.OnDemandRequestResponse.getData()
at response.OnDemandRequestResponse
下面显示的是我的JsonResponseModel类。
@XmlRootElement
public class TransactionStatusResponse {
public TransactionStatusResponse() {
}
public String transaction_id;
public String msn;
public String global_device_id;
public String type;
public String type_parameters;
public Timestamp command_receiving_datetime;
}
我也看到了java.sql.Timestamp中的类,它没有默认的构造函数。那么,有没有什么办法可以不发送默认参数的构造函数对象JSON响应。
我认为你需要为此注册适配器
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( TimestampAdapter.class)
public Timestamp done_date;
你应该使用java.util.Date代替java.sql.Date