0

I am using java OffsetDateTime to store time both on the client and server side. When I am sending the time information to the server, the local date time part looks like: "2021-06-15T15:43:50" and the offset is +02:00 (Central European Summer Time). However, when the time reaches my spring boot REST Service, it is deserialized as: "2021-06-15T13:43:50" with NO offset. Both the client AND the server are on the same host in central europe (my developper machine).

the field that is being serialized looks like this:

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX") private OffsetDateTime lastWriteTime;

Why do I have the zero offset on the server side? How can I have the "local" offset on the server side, too?

Greg
  • 1,227
  • 5
  • 23
  • 52
  • The deserialized time is exactly the same as the serialized time. The only difference is the time zone; the deserialized time is in UTC (i.e. no offset) – DwB Jun 15 '21 at 13:54
  • I realised that. I would like it to be deserialized to the OffsetDateTime with the offset representing the time zone. – Greg Jun 15 '21 at 13:57
  • I'm not sure this helps; take a look at https://stackoverflow.com/questions/46263773/jackson-parse-custom-offset-date-time – DwB Jun 15 '21 at 13:59
  • This Question could use an [MCVE](https://stackoverflow.com/help/mcve). – Basil Bourque Jun 15 '21 at 14:05
  • Replace `@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX")` with `@JsonSerialize(using = OffsetDateTimeSerializer.class) @JsonDeserialize(using = OffsetDateTimeDeserializer.class) @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX")` and let me know if it works. – Arvind Kumar Avinash Jun 16 '21 at 13:28

0 Answers0