java.sql.TimeStamp 没有默认构造函数

java.sql.TimeStamp doesn't have default constructor

我正在 Java 中编写我的 Web 服务,有一件事我卡住了。我想发送 java.sql.TimeStamp 作为 json 响应,但收到 IllegalAnnotationException。我正在使用 jersey 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

下面显示的是我的JsonResponseModelclass.

@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 class 并且它没有默认构造函数。那么,有什么方法可以在 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