Jackson @JsonFormat converting date with incorrect timezone

Utkarsh Gandhi :

I have a value coming in from JSON payload as:

"callStartTime" : "2019-03-27 13:00:00"

Entity.java

@JsonProperty("callStartTime")
@Column(name = "call_start_dt", nullable = false)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", lenient = OptBoolean.FALSE)
private Date callStartTime;

When I printed it on console, it says:

Wed Mar 27 08:00:00 CDT 2019

I wanted to be the same as it was in json payload. How I can fix it?

I am just taking date from json and writing it to mysql db in a datetime column.

Utkarsh Gandhi :

Simple solution: I solved it by changing the data type to String which completes my aim to capture the value as it is coming from JSON payload. Using Date and other data types were converting the value to some different timezone.

@JsonProperty("callStartTime")
@Column(name = "call_start_dt", nullable = false)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", lenient = OptBoolean.FALSE)
private **String** callStartTime;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=151017&siteId=1