Java 在@RequestBody的模型对象中使用sql.timestamp变量调用rest服务

Java 在@RequestBody的模型对象中使用sql.timestamp变量调用rest服务,java,json,rest,post,Java,Json,Rest,Post,如果我将变量firstDT从Timestamp更改为String,然后在get和set方法中从Timestamp转换为String,反之亦然,我知道如何运行下面的代码。我想知道是否有可能使下面的模型与时间戳变量一起工作 //Client: HttpPost postRequest = new HttpPost("http://localhost:8080/my_app/log/Mas60010"); ObjectMapper mapper = new ObjectMapper(); String

如果我将变量firstDT从Timestamp更改为String,然后在get和set方法中从Timestamp转换为String,反之亦然,我知道如何运行下面的代码。我想知道是否有可能使下面的模型与时间戳变量一起工作

//Client:
HttpPost postRequest = new HttpPost("http://localhost:8080/my_app/log/Mas60010");
ObjectMapper mapper = new ObjectMapper();
String json = "";

Map<String, String> map = new HashMap<String, String>();
map.put("subCd", "A");

SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
map.put("firstDT", "/Date(" + format.format(new Date()) + ")/");

map.put("messageFormat", "AFMAMXAS2CAPCISIMFMDSQSTSTRVIS");

json = mapper.writeValueAsString(map);

StringEntity input = new StringEntity(json);
input.setContentType("application/json");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);

//Rest Web Service:
@RequestMapping(value="Mas60010", method=RequestMethod.POST)
@ResponseBody
public String getFirst(@RequestBody Mas60010 mas60010) {
    return "I only reach here if firstDT is String ";
}

//Model
import java.sql.Timestamp;
public class Mas60010 {
       private String subCd;
       private Timestamp firstDT; // the doubt root is here
       private String messageFormat;
       public String getSubCd() {
              return subCd;
       }

       public void setSubCd(String subCd) {
              this.subCd = subCd;
       }

       public Timestamp getFirstDT() {
              return firstDT;
       }

       public void setFirstDT(Timestamp firstDT) {
              this.firstDT = firstDT;
       }

       public String getMessageFormat() {
              return messageFormat;
       }

       public void setMessageFormat(String messageFormat) {
              this.messageFormat = messageFormat;
       }

       @Override
       public String toString() {
         return "ok";
       }
}
//客户端:
HttpPostRequest=新的HttpPost(“http://localhost:8080/my_app/log/Mas60010");
ObjectMapper mapper=新的ObjectMapper();
字符串json=“”;
Map Map=newhashmap();
地图放置(“subCd”、“A”);
SimpleDateFormat=新的SimpleDateFormat(“MM/dd/yyyy HH:MM:ss”);
map.put(“firstDT”和“/Date(“+format.format(new Date())+”/”);
map.put(“messageFormat”、“AFMAMXAS2CAPCISIMFMDSQSTSTRVIS”);
json=mapper.writeValueAsString(map);
StringEntity输入=新的StringEntity(json);
setContentType(“应用程序/json”);
setEntity(输入);
HttpResponse response=httpClient.execute(postRequest);
//Rest Web服务:
@RequestMapping(value=“Mas60010”,method=RequestMethod.POST)
@应答器
公共字符串getFirst(@RequestBody Mas60010 Mas60010){
返回“如果firstDT是字符串,则我仅到达此处”;
}
//模型
导入java.sql.Timestamp;
公共级Mas60010{
私有字符串subCd;
private Timestamp firstDT;//怀疑根在这里
私有字符串格式;
公共字符串getSubCd(){
返回subCd;
}
公共void setSubCd(字符串subCd){
this.subCd=subCd;
}
公共时间戳getFirstDT(){
返回第一个dt;
}
public void setFirstDT(时间戳firstDT){
this.firstDT=firstDT;
}
公共字符串getMessageFormat(){
返回消息格式;
}
public void setMessageFormat(字符串messageFormat){
this.messageFormat=messageFormat;
}
@凌驾
公共字符串toString(){
返回“ok”;
}
}

我无法具体回答这个问题,但我只是尝试使用一个对象执行REST调用,该对象的字段变量类型为
java.sql.Timestamp
。我可以通过使用它的超类
java.util.Date
来解决这个问题。它不起作用的原因是
时间戳
没有空构造函数,而
日期
有空构造函数

嗨,我还在寻找这个问题的答案。在这个问题上没有人能帮我吗?嗨。。你找到解决办法了吗。。我也面临同样的问题。你的解决办法对我有帮助。请分享。。