Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Overview

Field names in JSON objects can be in a variety of formats. When we want to load those into our POJOs, we may encounter a problem where the property names in our Java code don’t match the naming convention in the JSON.

In this short tutorial, we’ll see how to deserialize snake case JSON to camel case fields using Jackson.

2. Install Jackson

Let’s start by adding the Jackson dependency to our pom.xml file:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.13</version>
</dependency>

3. Deserialize With the Defaults

Let’s consider an example User class:

public class User {
    private String firstName;
    private String lastName;

    // standard getters and setters
}

Let’s try to load this JSON, which uses the Snake Case naming standard (lowercase names separated by _):

{
    "first_name": "Jackie",
    "last_name": "Chan"
}

First, we need to use ObjectMapper to deserialize this JSON:

ObjectMapper objectMapper = new ObjectMapper();
User user = objectMapper.readValue(JSON, User.class);

However, when we try this, we get an error:

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "first_name" (class com.baeldung.jackson.snakecase.User), not marked as ignorable (2 known properties: "lastName", "firstName"])

Unfortunately, Jackson cannot exactly match the names in the JSON to the field names in User.

Next, we’ll learn three ways to solve this problem.

4. Use @JsonProperty Annotation

We can use the @JsonProperty annotation on the fields of our class to map the fields to the exact names in our JSON:

public class UserWithPropertyNames {
    @JsonProperty("first_name")
    private String firstName;
    
    @JsonProperty("last_name")
    private String lastName;

    // standard getters and setters
}

Now we can deserialize our JSON to a UserWithPropertyNames:

ObjectMapper objectMapper = new ObjectMapper();
UserWithPropertyNames user = objectMapper.readValue(JSON, UserWithPropertyNames.class);
assertEquals("Jackie", user.getFirstName());
assertEquals("Chan", user.getLastName());

5. Use @JsonNaming Annotation

Next, we can use @JsonNaming annotation on the class, and all fields will be deserialized using snake case:

@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class UserWithSnakeStrategy {
    private String firstName;
    private String lastName;

    // standard getters and setters
}

Then deserialize our JSON again:

ObjectMapper objectMapper = new ObjectMapper();
UserWithSnakeStrategy user = objectMapper.readValue(JSON, UserWithSnakeStrategy.class);
assertEquals("Jackie", user.getFirstName());
assertEquals("Chan", user.getLastName());

6. Configure the ObjectMapper

Finally, we can use the setPropertyNamingStrategy method on ObjectMapper to configure it for all serialization:

ObjectMapper objectMapper = new ObjectMapper()
  .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
User user = objectMapper.readValue(JSON, User.class);
assertEquals("Jackie", user.getFirstName());
assertEquals("Chan", user.getLastName());

As we see, we can now deserialize our JSON into the original User object, even though the User class doesn’t have any annotation.

We should note that there are other naming conventions (kebab case, for example), and the above solutions work with them as too.

7. Conclusion

In this article, we’ve seen different ways to deserialize snake case JSON to camel case fields using Jackson.

First, we explicitly named the fields. Then we set a naming strategy on the POJO itself.

Finally, we added a global configuration to the ObjectMapper.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.

 

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW