创建类Date2LongSerializer并extends JsonSerializer<Date> 重写serialize方法
public class Date2LongSerializer extends JsonSerializer<Date> {
@Override
public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvide) throws IOException, JsonProcessingException {
jsonGenerator.writeNumber(date.getTime() / 1000);
}
}
在需要转换类中的属性上加注解
/**创建时间*/
@JsonSerialize(using = Date2LongSerializer.class)
private Date createTime;
本文由博客一文多发平台 OpenWrite 发布!