I have an entity with java.time.Instant for created data field:
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public class Item {
private String id;
private String url;
private Instant createdDate;
}
I am using com.fasterxml.jackson.databind.ObjectMapper to save item to Elasticsearch as JSON:
bulkRequestBody.append(objectMapper.writeValueAsString(item));
ObjectMapper serializes this field as an object:
"createdDate": {
"epochSecond": 1502643595,
"nano": 466000000
}
I was trying the annotation @JsonFormat(shape = JsonFormat.Shape.STRING) but it doesn't work for me.
My question is how I could serialize this field as 2010-05-30 22:15:52 string?