On Fri, Sep 25, 2020 at 9:35 AM A. Rick Anderson
<[email protected]> wrote:
>
> Using custom serializer/deserializer classes, I've figured out how to work
> with LocalDate, with different formats, and in such a way that none of the
> client classes have to worry about the specific structure of my JSON DAO's.
> But, I haven't been able to figure out how to get from an JSON array of
> LocalDate to a Java List. A List<String> works great. Not so lucky with
> List<LocalDate>. Any suggestions?
>
> static public final DateTimeFormatter meetingTitleFormatter =
> DateTimeFormatter.ofPattern("dd MMMM yyyy");
> static public final DateTimeFormatter meetingIDFormatter =
> DateTimeFormatter.ofPattern("yyyyMMdd");
> static public final DateTimeFormatter meetingDateFormatter =
> DateTimeFormatter.ofPattern("yyyy-MM-dd");
> static public final DateTimeFormatter meetingShortDateFormatter =
> DateTimeFormatter.ofPattern("yyyy MMM dd");
> static public final DateTimeFormatter meetingLongDateFormatter =
> DateTimeFormatter.ofPattern("yyyy MMMM dd");
>
>
> @JsonProperty("StringDates")
> private List<LocalDate> PossibleMeetingDates = new ArrayList<>();
> @JsonDeserialize(using = MeetingShortDateDeserializer.class)
> @JsonSerialize(using = MeetingShortDateSerializer.class)
> @JsonProperty("MeetingShortDate")
> private LocalDate meetingShortDate;
> @JsonDeserialize(using = MeetingIDDeserializer.class)
> @JsonSerialize(using = MeetingIDSerializer.class)
> @JsonProperty("MeetingID")
> private LocalDate meetingID;
> @JsonDeserialize(using = MeetingDateDeserializer.class)
> @JsonSerialize(using = MeetingDateSerializer.class)
> @JsonProperty("MeetingDate")
> private LocalDate meetingDate;
> @JsonDeserialize(using = MeetingTitleDeserializer.class)
> @JsonSerialize(using = MeetingTitleSerializer.class)
> @JsonProperty("MeetingTitle")
> private LocalDate meetingTitle;
I think what you are looking for is
@JsonDeserialize(contentUsing = MeetingShortDateSerializer.class)
List<LocalDate> meetingShortDate;
since `using` refers to value itself, and to specify deserializer for
elements of a container you need to use `contentUsing` instead.
-+ Tatu +-
--
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/CAL4a10idFcCdkWQ_1H1N6X4T%3DvbfARkaOyfDiiVPXrMm-d8%3DwQ%40mail.gmail.com.