小编典典

Java json响应以数字值显示日期

java

@Data
public class Reponse {

    private String event;

    @Temporal(TemporalType.TIMESTAMP)
    private Date eventDate;

    private Double amount;
}

杰森的反应就像

{ 
  event: "transcation',
  eventDate: 1213123434,
  amount: 100
}

在这里,eventDate显示的是数值1540317600000而不是2018-10-23


阅读 315

收藏
2020-11-30

共1个答案

小编典典

您可以使用注释该字段@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")。然后,响应时间格式将类似于“ yyyy-MM-dd HH:mm

import com.fasterxml.jackson.annotation.JsonFormat;


public class Reponse {

    private String event;

    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
    private Date eventDate;

    private Double amount;
}
2020-11-30