Showing posts with label Jackson API. Show all posts
Showing posts with label Jackson API. Show all posts

Saturday, July 19, 2025

Mastering @JsonFormat in Jackson: A Complete Guide with Examples

If you're working with Java and JSON, the Jackson library is likely part of your tech stack. One of the most powerful yet underused annotations it provides is @JsonFormat.

In this ultimate guide, we’ll break down what @JsonFormat does, when to use it, and how to handle advanced scenarios with fully working examples. This post is optimized for SEO to help developers find quick and accurate answers.


✅ What is @JsonFormat in Jackson?

@JsonFormat is a Jackson annotation that helps control how Java fields are serialized (Java to JSON) or deserialized (JSON to Java). This is especially useful for dates, enums, and number formats.

Import Statement:


import com.fasterxml.jackson.annotation.JsonFormat;

Dependencies

Make sure you include the correct Jackson modules for java.time:


 <dependency>
   <groupId>com.fasterxml.jackson.datatype</groupId>
   <artifactId>jackson-datatype-jsr310</artifactId>
   <version>2.15.3</version>
 </dependency>
 

And register it:


 ObjectMapper mapper = new ObjectMapper();
 mapper.registerModule(new JavaTimeModule());
 

Tuesday, November 17, 2020

Jackson API - JSON String To Object In Java

1. Introduction


In this tutorial, We'll learn how to convert or transform JSON into a Java Object using Jackson API. This can be achieved in many ways using Jackson api and other GSON, JSONParser API.

Example:

String jsonString = "
 {
  "name": "nadal",
  "age": "35",
  "gender": "M"
 }";

This class needs to be converted to a Customer object.

Jackson API - JSON String To Object In Java


Tuesday, May 19, 2020

Jackson API @JsonAnyGetter Annotation - Map Example

1. Introduction


In this Jackson Annotation Series, You'll be learning @JsonAnyGetter annotation and example program to demonstrate @JsonAnyGetter annotation with Map Example in Jackson API.

Jackson API is mainly integrated with Java tech stack.

Mainly @JsonAnyGetter is used on Map<String, String> property which holds the additional properties which are apart from the normal properties.

Please note that @ JsonAnyGetter is a method level annotation and can not be used on the filed level. If you use so on field level will cause a compile-time error.

This is the first annotation in our series.


Jackson API @JsonAnyGetter Annotation - Map Example

Sunday, May 17, 2020

Joda Datetime Jackson DeSerialization - @JsonDeserialize

1. Introduction


In this tutorial, You'll learn how to deserialize the Joda DateTime object when working with Jackson JSON to Object conversion java 8.

Jackson String JSON to Object

Jackson API @JsonDeserialize annotation is to use for the custom deserializer and also is to parse the dates using " com.fasterxml.jackson.databind.deser.std.StdDeserializer<DateTime>" class from to Joda API datetime to String.


Joda Datetime Jackson DeSerialization - JSON to Object @JsonDeserialize