[在我的实体中定义了一个时态:
@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",
您可以使用杰克逊的DateFormat
批注:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssZ")