[英]jackson timestamp mapping bug?
I get the data from the mobile client as the json file. 我从移动客户端获取数据作为json文件。
But, if only the time stamp, it can not normally receive data. 但是,如果仅是时间戳记,则通常无法接收数据。 In the end, truncated 3-digit number. 最后,截断的3位数字。
So the date is completely wrong. 所以日期是完全错误的。
This is my source. 这是我的资料。
json file json档案
{
"startPhotoAddress": "Great Ocean Road, Hordern Vale",
"createTimeStamp": "1356998400",
"startPhotoTimeStamp": "1356998430"
}
In the controller 在控制器中
@RequestMapping(value = "/moment", method = RequestMethod.POST, headers = "Accept=application/json")
public @ResponseBody JsonNode setMomentJson(HttpServletRequest request, @RequestBody Moment moment){
In the model 在模型中
import java.sql.Timestamp;
public class Moment{
private Timestamp createTimeStamp;
public Timestamp getCreateTimeStamp() {
return createTimeStamp;
}
public void setCreateTimeStamp(Timestamp createTimeStamp) {
this.createTimeStamp = createTimeStamp;
}
}
I get createTimeStamp : 1970-01-17 01:56:38.4 我得到createTimeStamp:1970-01-17 01:56:38.4
it use only 1356998 from 1356998400 of createTimeStamp. 它仅使用createTimeStamp的1356998400中的1356998。
If it receive a string, not a problem. 如果收到字符串,则不成问题。
Please, what is the problem? 拜托,这是什么问题? Thanks in advance for your help. 在此先感谢您的帮助。
If your are receiving timestamp values in seconds, not milliseconds, you can make a setter to accept a long type and multiply the input value on 1000, and create a Timestamp instance by calling a constructor. 如果您以秒而不是毫秒为单位接收时间戳值,则可以使setter接受长型并将输入值乘以1000,然后通过调用构造函数来创建Timestamp实例。 Something like this: 像这样:
public class Moment{
private Timestamp createTimeStamp;
public Timestamp getCreateTimeStamp() {
return createTimeStamp;
}
public void setCreateTimeStamp(long createTimeStamp) {
this.createTimeStamp = new Timestamp(createTimeStamp * 1000);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.