- public SerializationConfig with(DateFormat df) {
- SerializationConfig cfg = (SerializationConfig)super.with(df);
- return df == null ? cfg.with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) : cfg.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
- }
- public final void defaultSerializeDateValue(long timestamp, JsonGenerator gen) throws IOException {
- if (this.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) {
- gen.writeNumber(timestamp);
- } else {
- gen.writeString(this._dateFormat().format(new Date(timestamp)));
- }
- }
- public final void defaultSerializeDateValue(Date date, JsonGenerator gen) throws IOException {
- if (this.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) {
- gen.writeNumber(date.getTime());
- } else {
- gen.writeString(this._dateFormat().format(date));
- }
- }
- public class Event {
- public String name;
- @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
- public Date eventDate;
- }
- public class CustomDateSerializer extends StdSerializer<Date> {
- //...
- }