I am upgrading my spring boot application to spring boot 2.7.8 and Java 11. I getting different rest response of ZonedDateTime object after upgrade.
My request contain "2023-06-23T18:13:06.630Z[UTC]", and I am returning same request object as a Map key in response. But in response ending 0's from millisecond part getting trimmed "2023-06-23T18:13:06.63Z[UTC]".
Request:
{
"dateList": [
"2023-06-23T18:13:06.630Z[UTC]"
]
}
Response:
{
"dateList": {
"2023-06-23T18:13:06.63Z[UTC]": "2023-06-23T11:13:06.630-07:00"
}
}
Did someone faced earlier this issue?
Any solution to this issue, As I am using as Map key of ZonedDateTime, I need to keep it consistent.
This is a known issue with Jackson that affects the serialization of
ZonedDateTimeobjects.This issue is caused by the fact that Jackson by default uses Java's built-in DateTimeFormatter to serialize and deserialize dates and times, so this format does not preserve trailing zeros in milliseconds.
To fix this issue, you can configure Jackson to use a custom date/time format that preserves trailing zeros in milliseconds
I tried this and by creating a custome config for jackson:
P.S :Also you can use this formatter to format your ZonedDateTime objects before adding them to the map: