Why Lombok-generated getters cause JSON fields to become lowercase

The article explains how Lombok’s @Data annotation generates getter and setter methods with a lowercase first letter for camel‑case fields, causing Jackson to serialize JSON property names in all lowercase, and offers three fixes: write methods manually, use @JsonProperty, or rename fields to avoid lower‑upper patterns.

Coder Trainee
Coder Trainee
Coder Trainee
Why Lombok-generated getters cause JSON fields to become lowercase

Problem Background

When returning data to the front‑end, the author observed that all field names that should follow camelCase (e.g., xCoordinate) were automatically converted to all‑lowercase in the JSON response.

Correct JSON should preserve the original camelCase naming.

Analysis

The interface uses a cache and wraps the response in a custom response entity instead of returning the database‑mapped entity directly.

Suspected Issues

Fields in the response entity might have been written in lowercase.

The cache could be converting case during serialization.

Investigation

The author verified that both the response entity and the database‑mapped entity have correct field definitions and that the transformation process initially uses uppercase field names.

Removing the cache did not change the outcome; the JSON still contained lowercase field names.

Further inspection revealed that the getters and setters were generated by Lombok’s @Data annotation.

Root Cause

Lombok generates getter and setter method names by lower‑casing the first character of the field name. For a field named xCoordinate, Lombok produces getxCoordinate() and setxCoordinate(). Jackson, which Spring MVC uses for JSON serialization, relies on these method names to infer property names, resulting in the JSON keys being rendered as xcoordinate (all lowercase).

public String getXCoordinate() {
    return this.xCoordinate;
}

public String getYCoordinate() {
    return this.yCoordinate;
}

In contrast, manually written methods preserve the capital letter after the first character:

public String getxCoordinate() {
    return this.xCoordinate;
}

public void setxCoordinate(String xCoordinate) {
    this.xCoordinate = xCoordinate;
}

public String getyCoordinate() {
    return this.yCoordinate;
}

public void setyCoordinate(String yCoordinate) {
    this.yCoordinate = yCoordinate;
}

The difference makes it clear why the JSON output was incorrectly lowercased.

Solution

Manually write getter and setter methods instead of relying on Lombok.

Use Jackson’s @JsonProperty("yCoordinate") (or the appropriate name) to explicitly define the JSON field name.

Avoid naming fields with a lowercase letter followed by an uppercase letter when using Lombok (e.g., rename xCoordinate to coordinateX or similar).

The issue is resolved by applying one of the above approaches.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaJSONJacksonSpring MVCLombokcamelCase
Coder Trainee
Written by

Coder Trainee

Experienced in Java and Python, we share and learn together. For submissions or collaborations, DM us.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.