JSON Data format

0

Hello, I have a webservice that needs to fetch some data in the database and return a json object and I'm having problems with the date.

here is the object

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;


@XmlRootElement
public class Carro{

    @XmlElement
    private String id;

    @XmlElement
    private String nome;

    @XmlElement
    private Timestamp dtFabricacao;
... gets and setters

}

I go to the database and fill in the properties of the class normally the date gets "dd / mm / yyyy HH: mm: ss z"

but json stays with it

{
"id": 1
"nome": "Fiesta"
"dtFabricacao": 152679516567919
}

I've tried to create a serialization class and anotations and nothing works anymore I do not know what to do anymore.

I'm using jax and jackson to convert the object to json and my project uses maven

    
asked by anonymous 10.10.2017 / 22:11

1 answer

1

This is the format of the date in Json, if you are using javascript to consume this service you can use the date like this:

var date = new Date(152679516567919);
alert(date);

If you want to format in another way you can use this nice plugin:

$.format.date(new Date(), 'yyyy/MM/dd HH:mm:ss');

link

If you want to send in the format you see in the database, create another property, however, as a string type of this code and fill in with the formatted value:

@XmlElement
private String dtFabricacao;
    
10.10.2017 / 23:07