我有一个java.time.Instant创建数据字段的实体:
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public class Item {
private String id;
private String url;
private Instant createdDate;
}
Run Code Online (Sandbox Code Playgroud)
我com.fasterxml.jackson.databind.ObjectMapper用来将项目保存为Elasticsearch作为JSON:
bulkRequestBody.append(objectMapper.writeValueAsString(item));
Run Code Online (Sandbox Code Playgroud)
ObjectMapper 将此字段序列化为对象:
"createdDate": {
"epochSecond": 1502643595,
"nano": 466000000
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试注释,@JsonFormat(shape = JsonFormat.Shape.STRING)但它对我不起作用.
我的问题是如何将此字段序列化为2010-05-30 22:15:52字符串?