I am struggling with mentioned in the question issue.
I need to create some custom deserializer which is more or less type conversion from the standard deserializer (reason is that ZonedDateTime
is working for my input, but I don't want to change the type to ZonedDateTime
, but keep LocalDateTime
).
Bascially what I want to do in my deserializer is to:
- Deserialize using
ZonedDateTime
deserializer (which I found, in reality, is customInstantDeserializer
) - Use
.toLocalDateTime
and return it.
How can I use it? Was trying to find it but I can't.
If your input represents a
ZonedDateTime
and you want to convert it to aLocalDateTime
, you can do the following.I've created a sample class with a
LocalDateTime
field:And also created the deserializer class:
I've tested with the input
2017-07-05T14:10:45.432+01:00[Europe/London]
and the result was aLocalDateTime
with the value2017-07-05T14:10:45.432
.If the input is in a different format, then you need to use this format in the
CustomZonedToLocalDeserializer
class (instead of usingDateTimeFormatter.ISO_ZONED_DATE_TIME
, you'd useDateTimeFormatter.ofPattern(pattern)
).@JsonDeserialize is used to indicate the use of a custom deserializer
And the custom deserializer is as follows:
The demo can be accessed in github
Maven dependency