I have a class like this:
public class Foo {
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
@JsonSerialize(contentUsing = LocalDateSerializer.class)
private Optional<LocalDate> localDate;
}
I then serialize the class using an ObjectMapper
, registering both Jdk8Module
and JavaTimeModule
.
However, I'm getting a JSON that I'm not expecting: For LocalDate.of(2020, 4, 1)
, it gets serialized to the following: (code formatted for clarity)
{
"localDate": [2020, 4, 1]
}
instead of:
{
"localDate": "2020-04-01"
}