Cannot construct instance of `java.time.LocalDate` - Spring boot, elasticseach, jackson
add below annotation over the field LocalDate
@JsonDeserialize(using = LocalDateDeserializer.class)@JsonSerialize(using = LocalDateSerializer.class)private LocalDate start;
Date/time format, according to ISO 8601 is "YYYY-MM-DD", so your pattern should be:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
Instead of:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd.MM.yyyy")
Another way is adding in your application.yml
spring: jackson: serialization: WRITE_DATES_AS_TIMESTAMPS: false
Or disable this feature directly in your object mapper:
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
need to install JsonFormat JsonDeserialize JsonSerialize
private LocalDate dateOfBirth; @PastOrPresent(message = "must be past time or present") @Column(name = "date_of_birth", nullable = false, columnDefinition = "DATE") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) @JsonSerialize(using = LocalDateSerializer.class) public LocalDate getDateOfBirth() { return dateOfBirth; } @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy") public void setDateOfBirth(LocalDate dateOfBirth) { this.dateOfBirth = dateOfBirth; }