Json node get asLocalDate


Good day,

Please assist, I checked Jackson JsonNode but I can’t seem to find what am looking for.

I need to know how to get JsonNode as LocalDate

// Example : I can get int value like :

ObjectMapper mapper = new ObjectMapper();
final JsonNode data =mapper.readTree(json);
Int myNumberInt = data.get ("ngNumberInt").asInt();

How about LocalDate, how do I get it from JsonNode?

In my mind, am wishing there was

LocalDate dateCreated = data.get ("ngDate").asLocalDate(); 


JsonNode methods will only give you the JSON data types. However you can use your ObjectMapper instance to deserialize a LocalDate.

objectMapper.readValue(data, LocalDate.class)

You will need to include jackson-modules-java8 if you haven’t already. This includes a serializer/deserializer for Java’s LocalDate.

Answered By – Gorazd Rebolj

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published