I have an error when I try to deserialize this attribute:
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime deliveryDate;
This is the deserialization class:
public class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
@Override
public LocalDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException {
if (parser.getCurrentToken().equals(JsonToken.VALUE_STRING)) {
String rawDate = parser.getText();
return LocalDateTime.parse(rawDate);
} else {
throw context.wrongTokenException(parser, JsonToken.VALUE_STRING, "Expected string.");
}
}
And the serialization class:
public class LocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeString(value.toString());
}
This is the error I get:
"timestamp":1513962011642,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read document: Text '2017-12-22T16:00:00.874Z' could not be parsed, unparsed text found at index 23
Do you know why?
Thanks!