1.Date对象定义如下:
/**创建时间**/
private Date createTime
/**修改时间**/
private Date updateTime
2.定义一个类继承JsonSerializer<Date>类
public class Date2LongSerializer extend com.fasterxml.jackson.databind.JsonSerializer<Date>{
@Override[override]
public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider SerializerProvider) throws IOException {
jsonGenerator.writeNumber(date.getTime()/1000);
}
}
3.在定义的Date类上添加@JsonSerialize注解
/**创建时间**/
@JsonSerialize(using = Date2LongSerializer.class)
private Date createTime
/**修改时间**/
@JsonSerialize(using = Date2LongSerializer.class)
private Date updateTime