I'm parsing a ZonedDateTime
using like this:
@JsonSerialize(using = ZonedDateTimeSerializer.class)
private ZonedDateTime expirationDateTime;
I need to be able to properly deserialize this date. However, there is no deserializer for this that is provided by jackson:
com.fasterxml.jackson.datatype.jsr310.deser
Is there a reason why it's missing? What is the most common workaround?
Updated: Here is my scenario:
I create ZonedDateTime
like this:
ZonedDateTime.of(2017, 1, 1, 1, 1, 1, 1, ZoneOffset.UTC)
Then I serialize the object that contains the date like this:
public static String toJSON(Object o) {
ObjectMapper objectMapper = new ObjectMapper();
StringWriter sWriter = new StringWriter();
try {
JsonGenerator jsonGenerator = objectMapper.getJsonFactory().createJsonGenerator(sWriter);
objectMapper.writeValue(jsonGenerator, o);
return sWriter.toString();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
And when I try to send it to Spring MVC Controller:
mockMvc.perform(post("/endpoint/")
.content(toJSON(myObject))
.contentType(APPLICATION_JSON))
.andExpect(status().isOk());
The date object that goes inside the controller is different.
Before: 2017-01-01T01:01:01.000000001Z
After: 2017-01-01T01:01:01.000000001Z[UTC]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With