I'm using spring boot 2, and I have a class which has java.sql.Date and also java.sql.Timestamp properties. I need to serialize the Timestamp as nanoseconds and serialize the Date as standard format (yyyy-MM-dd).
At first the JSON result is like below :
"checkinTime": "2019-05-01T17:00:00.000+0000", // java.sql.Timestamp
"lastOrderDate":"2019-05-01" // java.sql.Date
And then I put these lines in the application.properties file
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS: true
spring.jackson.serialization.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS: false
After that the result is like below :
"checkinTime": -2209014000000,
"lastOrderDate": 1556643600000,
What I want is like this
"checkinTime": -2209014000000, // java.sql.Timestamp
"lastOrderDate":"2019-05-01" // java.sql.Date
How can I achieve this in spring boot ??
checkinTimeis written as ISO-8601, not a timestamp. (1) Use Instant in your DTO (and probably entity) and (2) turn off timestamps.WRITE_DATES_AS_TIMESTAMPSto false.