Serialize/deserialize java 8 java.time with Jackson JSON mapper

If you are having POJO where you have declared LocalDate or LocalDateTime and have this error while running with java 8.

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.LocalDateTime` 
not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling

Then as the error is stating first, install the dependency jackson-datatype-jsr310.

implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'

And then annotate your POJO fields that have LocalDate or LocalDateTime to serialize and deserialize using the LocalDate’s serializer and deserializer.

@JsonProperty("created_at")
@JsonSerialize(using = LocalDateSerializer.class)
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate createdAt;

@JsonProperty("updated_at")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime updatedAt;

And the annotation will serialize and deserialize the JSON using those classes.