#Springboot rest controller and Date class

11 messages · Page 1 of 1 (latest)

muted marshBOT
#

This post has been reserved for your question.

Hey @reef condor! Please use /close or the Close Post button 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.

cedar wasp
#

are you sure the offset isn't different?

#

one of them should be either +2 or -2

candid anvil
#

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

cedar wasp
#

unless if yo're goign to hardcode itas +2 but what about daylight savings etc

candid anvil
# cedar wasp but you can't magically invent a timezone?

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

muted marshBOT
#

💤 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.