
It handles the object being int id a string pretty well, but it needs help converting the string 2020-04-12 to an object LocalDate. It does this using a custom module, which defines a JSON mapping for custom object types. Jackson Data Binding: Custom Styles For mapping LocalDate, Jackson provides a dependency . Add this to your project and configure your ObjectMapper as follows: Java Copy the code ObjectMapper objectMapper = new ObjectMapper() .
registerModule(new JavaTimeModule()); [ this code in the example directory ] Jackson Data Binding: Custom Field Names You may have noticed that I used <key> closeApproachDate in my JSON example above, while NASA's data uses <key> close_approach_date.
I did this because Jackson will use Java's reflection capabilities to match the JSON keys to the Java field names (and they must match exactly).
Most of the time, you can't modify your JSON: it usually comes from an API that you don't control. But you still want to avoid having fields written in snake_case your Java classes. This is possible with an annotation on the field closeApproachDate : Java Copy the code @JsonProperty("close_approach_date") public LocalDate closeApproachDate; [ this code in the example directory ] Creating Custom Objects with JsonSchema2Pojo You’re probably thinking that all this is time-consuming.