简体   繁体   中英

jackson timestamp mapping bug?

I get the data from the mobile client as the json file.

But, if only the time stamp, it can not normally receive data. In the end, truncated 3-digit number.

So the date is completely wrong.

This is my source.

json file

{
  "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

it use only 1356998 from 1356998400 of createTimeStamp.

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. 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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM