Jackson ObjectMapper
About
Dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency><dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>Spring Integration
How Spring Boot Uses Jackson Internally ?
Default Behavior in Spring Boot
Example Defaults
Feature
Default Behavior
Customizing ObjectMapper via application.yml
application.ymlInternally, Spring Boot does this
Overriding the Default ObjectMapper
Use Cases
1. Serialization: Java Object to JSON
2. Deserialization: JSON to Java Object
3. Convert Between Java Objects (Object to Object Mapping)
4. Convert to and from Map
POJO Class
Convert POJO to Map
Convert Map to POJO
5. Handling Collections and Generics
6. Deserialization with Unknown or Partial JSON
POJO Class
JSON with Extra Field (unknown)
Default Behavior (in Spring Boot)
Manually Ensuring it Ignores Unknown Fields
Partial JSON
Serialization Inclusion Strategies
Options
Strategy
Description
Global Configuration
Field-Level Configuration
Spring Boot Configuration (application.yml)
Use Case Example
Date and Time Handling
Why Special Handling Is Needed
Solution
Field-Level Formatting
Global Formatting in Spring Boot
Timezone Handling
Deserialization Considerations
Field Naming Strategy
Default: camelCase
snake_case:
Spring Boot Configuration
Use Case
Working with JSON Tree (JsonNode)
Parsing JSON as Tree
Modifying Tree
Traversing Nested Nodes
Creating a Tree Manually
Use Case
Annotations for Fine-Grained Control
Common Annotations
Annotation
Purpose
Examples
Use Case
Working with JSON Tree (JsonNode)
Parsing JSON as Tree
Modifying Tree
Traversing Nested Nodes
Creating a Tree Manually
Use Case
Exception Handling
Common Exceptions
Exception
Cause
Spring REST Exception Handler
Custom Serializers and Deserializers
1. Custom Serializer
Goal: Control how a Java object or field is written to JSON.
Steps:
2. Custom Deserializer
Goal: Control how JSON is parsed into a Java object or field.
Steps:
3. Apply to Entire Class
Example: Serialize full object to flat string
4. Global Registration
5. Use with Spring Boot's Default ObjectMapper
Last updated