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