How to create custom serialization for java calendar for json by extending json serializer<Calendar>?
I have tried the same for java.until.Dateand it works. In the serialization method, I converted Date to String and wrote it in json format.
The sample code made for java.util.Date is similar to the code below
public class CDJsonDateSerializer extends JsonSerializer<Date>{
@Override
public void serialize(Date date, JsonGenerator jsonGenerator,SerializerProvider provider)
throws IOException {
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
String dateString = dateFormat.format(date);
jsonGenerator.writeString(dateString);
}
}
And it is used like this:
@JsonSerialize(using = CDJsonDateSerializer.class)
private Date startDate;
What can I do to serialize a calendar in java for json without losing data in a Calendar object?
source
share