I am having some issue with date logic which I've isolated to Jackson, the JSON serializer.
In the database and in a debug point in the application, dates are correct and everything is written using default timezone. However, in serialization 4 hours are being added. I found this could be remedied by telling Jackson specifically to use EST (it was defaulting to UTC). As below:
@JsonFormat(shape= JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss.SSSZ", timezone="America/New_York")
private Date startDate;
However, the problem is that only local is using EST and the server will be using UTC. I need Jackson to use system defaults.
Luckily, I found this similar question which is backed up by the documentation. New solution:
@JsonFormat(shape= JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss.SSSZ", timezone=JsonFormat.DEFAULT_TIMEZONE)
private Date startDate;
However, it doesn't work! I tried also timezone='DEFAULT_TIMEZONE'
and a variety of other things but in all cases the api output still seems to be 4 hours ahead of the number in the database.
Other things I have tried:
- logging out
JsonFormat.DEFAULT_TIMEZONE
returns##default
. - logging
TimeZone.getDefault().getDisplayName()
returnsEastern Standard Time
.
Jackson version is 2.9.
Any suggestions?