#Springboot rest controller and Date class
11 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @reef condor! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Date doesn't store a ZoneId. So the conversion loses precision, since Jackson doesn't know the date is actually UTC+2
I'd make a custom Deserializer for Date, then you either register it as a simple module to the object mapper, or annotate the fields in the DTO with an annotation that is escaping me. @DeserializeWith comes to mind, but I know that is wrong.
Sorry brain is still waking up. That should be a custom JsonSerializer, and then you annotate with@JsonSerialize(using=MyCustomSerializer.class
but you can't magically invent a timezone?
unless if yo're goign to hardcode itas +2 but what about daylight savings etc
The offset OP is referring to is an implicit offset, known by the developers, not by the code. So when Spring converts the Date, it doesn't factor in the implicit offset, causing the date to be off by 2 hours. The custom Serializer is allow OP to "tell" Spring about the implicit offset, by handling it themself, without swapping the DTO to use ZonedDateTime or OffsetDateTime
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.