我的实体中的时间定义如下:
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "start_time", length = 19, nullable = false)
public Date getStartTime() {
return this.startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
像这样编码 JSON 输出(简化):
@GET
@RestSecure
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public Response list(){
return Response.status(Response.Status.OK).entity(myEntityList).build();
}
是否有一种简单的方法来覆盖输出日期格式?
我得到的是这样的时代:
"startTime": 1582261711000,
我需要的是 ISO 8601 格式的日期,如下所示:
"startTime": "2020-02-21T05:08:31Z",
最佳答案
您可以使用 Jackson 的 DateFormat
注释:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssZ")
关于java - Hibernate - 生成 JSON 时覆盖日期的输出格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60677503/