Skip to content

ayagamal-tech/jackson-data-binding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jackson-data-binding

A simple Java application demonstrating how to map JSON to POJO using the Jackson library.

Technologies Used

  • IDE Intellij IDEA
  • Java Version JDK 1.8 (Java 8)
  • Maven Dependencies:
    • jackson-core (v2.16.1)
    • jackson-databind (v2.16.1)

Errors and Troubleshooting

If you are testing this code and remove some parts, you might run into this error:

Exception in thread "main" com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of Student (no Creators, like default constructor, exist): cannot deserialize from Object value no delegate- or property-based Creator ....

Why it happens: Jackson requires a blank, default constructor (such as public Student() { }) to build the empty object before it can inject the JSON data.

Same Solution for similar case: If you're interested, you can read this discussion: Stackoverflow Discussion

Concepts Demonstrated

  • Basic Data Binding: Converting flat JSON to Java Objects.
  • Nested Objects: Mapping JSON objects within objects to separate custom POJOs (such as mapping a director JSON object to a Director.java class).
  • Collections: Automatically mapping JSON arrays to Java List<String>.
  • Jackson Annotations:
    • @JsonProperty: Resolving naming convention mismatches between JSON (snake_case or capitalized fields) and Java (camelCase).
    • @JsonIgnore: Securing sensitive data by ignoring specific fields during serialization (hiding internal variables from the final JSON output).

About

A simple Java application demonstrating how to map JSON to POJO using the Jackson library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages