Why is the hour wrong in a java.sql.Timestamp field annotated with Jackson's @JsonFormat?
The problem is because of missing timezone attribute. I think JSON is using UTC as timezone and applying the convertion, but this worked for me.
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" ,timezone="IST") private Timestamp time;
OR if you wanna set it at global level for all Timestamp
ObjectMapper mapper = new ObjectMapper(); mapper.setTimeZone(TimeZone.getTimeZone("IST"));
Btw , this also works for me.
ObjectMapper mapper = new ObjectMapper(); mapper.setDateFormat(sdf);