ConvertersLesson 30Free preview
JSON to Java
This lesson is part of Web Developer Tools · All levels
Summary
The JSON to Java converter produces a POJO class with a field that matches the key name on the JSON. Each field has a type such as a String, int, boolean, or List, and can be equipped with a getter and a setter. To read JSON into an object, use a library like Jackson or Gson with a mapping annotation when the field name is different. The resulting converter needs to be adjusted to the Java naming rules and the possible value null.
Key points
- Creating a POJO class with a field according to the JSON key
- The type of field is selected based on the value, e.g. String or int
- Annotations like @JsonProperty help map specific key names
- Jackson and Gson is a popular library for serialization
- The name of the Java field is generally camelCase, as opposed to the JSON key
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.