date格式序列化

//需要添加自定义序列化类
@Component
public class JsonDateSerializer extends JsonSerializer<Date> {

    @Override
    public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String formattedDate = DateUtils.datetimeFormat.format(date);
        jsonGenerator.writeString(formattedDate);
    }
}
    @Data
    public static class ManageListResp {
        private Integer id;
        private String outOrderNo;
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @JsonSerialize(using = LocalDateTimeSerializer.class)
        private LocalDateTime createTime;
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        //指定自定义序列化
        @JsonSerialize(using = JsonDateSerializer.class)
        private Date gmtTrans;
        private Integer depositChannel;
        private String serial;
        private String deviceCode;
        private String trueName;
        private String mobile;
    }
posted @ 2021-06-10 11:41  cchilei  阅读(331)  评论(0编辑  收藏  举报