ObjectMapper
Jackson's main class, which converts objects to JSON with writeValueAsString and JSON to typed objects with readValue, following its configured rules.
In more detail
An ObjectMapper is expensive to build and safe to share, so an application should create one configured instance and inject it wherever needed; Spring Boot does this for you. Tests should use the same configuration so they assert the real wire format.
Examples
String json = mapper.writeValueAsString(message);Message m = mapper.readValue(json, Message.class);Related terms
- Jackson — The most widely used Java library for converting between Java objects and JSON, and the default in Spring Boot.
- naming strategy — A Jackson setting that converts Java names into different JSON field names, for example itemCount into item_count.
- unknown properties — JSON fields in incoming data that the target Java type does not declare, which a mapper can either reject or ignore.
- dependency injection — Giving an object the collaborators it needs from outside, usually through its constructor, instead of letting it create or look them up itself.
Taught in
- Working With Jackson — Modern Java: Virtual Threads & High-Throughput Services