I'm trying to serialize an Object that contains a List of Dates and i want to serialize to a JSON list of dates (String) in a specific format (yyyy-MM-dd).
private List<Date> executionDates;
will become like:
"executionDates": [
"2016-07-22",
"2016-07-23",
"2016-07-24"
]
It is possible to do it with annotations?
Thanks in advance.
I found the solution. I had to use property contentUsing
instead of using
in annotation like this:
@JsonSerialize(contentUsing = JsonDateSerializer.class)
contentUsing property is used for collections. From class documentation:
Serializer class to use for serializing contents (elements of a Collection/array, values of Maps) of annotated property. Can only be used on properties (methods, fields, constructors), and not value classes themselves (as they are typically generic).
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