Hello:
How can I use annotations to deserialize Greenwich Time into LocalTime?
Here is Demo class:
public class Demo implements Serializable { private LocalDateTime time; //
setter getter ... }
Here is Demo JSON:
{"time" : "2019-05-08T07:45:44.519Z"}
The time I expect to get is 2019-05-08T15:45:44.519, but what I get is:
2019-05-08T07:45:44.519
Now I'm using custom deserialized classes to solve the problem:
public class LocalDateTimeDeserializer extends
JsonDeserializer<LocalDateTime> { private static final String ZULU = "Z";
@Override public LocalDateTime deserialize(JsonParser jsonParser,
DeserializationContext deserializationContext) throws IOException,
JsonProcessingException { String text = jsonParser.getText(); if
(text.endsWith(ZULU)) { return LocalDateTime.ofInstant(Instant.parse(text),
ZoneId.systemDefault()); } else { return LocalDateTime.parse(text,
DateTimeFormatter.ISO_LOCAL_DATE_TIME); } } } public class Demo implements
Serializable { @JsonDeserialize(using =
CustomLocalDateTimeDeserializer.class) private LocalDateTime time; //
setter getter ... }
Is there any other way?
I would appreciate your help.
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jackson-user/d5c003d3-6775-4aa1-92fc-90763203bf5en%40googlegroups.com.