question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`SNAKE_CASE` doesn't work when using Lombok's `@AllArgsConstructor`

See original GitHub issue

SNAKE_CASE doesn’t work when using Lombok’s @AllArgsConstructor in 1.7.3 but it (CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES) works regardless of using @AllArgsConstructor in 1.6.5.

This is a sample test to show the problem:

public class ObjectMapperLombokAllArgsConstructorTests {

    @Test
    public void test() throws JsonProcessingException {
        LombokAllArgsConstructorDomain lombokDomain = new LombokAllArgsConstructorDomain();
        lombokDomain.setSomeProperty("test");
        String lombokJson = new ObjectMapper()
                .setPropertyNamingStrategy(
                        PropertyNamingStrategy.SNAKE_CASE)
                .writeValueAsString(lombokDomain);
        System.out.println(lombokJson);

        ManualAllArgsConstructorDomain manualDomain = new ManualAllArgsConstructorDomain();
        manualDomain.setSomeProperty("test");
        String manualJson = new ObjectMapper()
                .setPropertyNamingStrategy(
                        PropertyNamingStrategy.SNAKE_CASE)
                .writeValueAsString(manualDomain);
        System.out.println(manualJson);

        String workaroundAppliedLombokJson = new ObjectMapper()
                .enable(MapperFeature.ALLOW_EXPLICIT_PROPERTY_RENAMING)
                .setPropertyNamingStrategy(
                        PropertyNamingStrategy.SNAKE_CASE)
                .writeValueAsString(lombokDomain);
        System.out.println(workaroundAppliedLombokJson);
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    static class LombokAllArgsConstructorDomain {

        private String someProperty;

    }

    @Data
    @NoArgsConstructor
    static class ManualAllArgsConstructorDomain {

        private String someProperty;

        public ManualAllArgsConstructorDomain(String someProperty) {
            this.someProperty = someProperty;
        }

    }

}

You can also find it in the following location to test immediately: https://github.com/izeye/samples-java-branches/blob/master/src/test/java/learningtest/com/fasterxml/jackson/databind/ObjectMapperLombokAllArgsConstructorTests.java

This was originally reported at: https://github.com/spring-projects/spring-boot/issues/5687

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Shredder121commented, Apr 20, 2016

I also confirmed that it works, since I was one of the people who pushed for @ConstructorProperties support. Sorry for the hassle 😅 Keep up the good work.

0reactions
Shredder121commented, Apr 20, 2016

If you need any testing, feel free to ping me. It was merely chance that I stumbled upon this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Immutable Lombok annotated class with Jackson
Create a lombok.config file in an appropriate location with the ... Then serialization and deserialization by Jackson works as expected.
Read more >
Constructor Injection in Spring with Lombok - Baeldung
With Lombok, it's possible to generate a constructor for either all class's fields (with @AllArgsConstructor) or all final class's fields ...
Read more >
onX - Project Lombok
On javac8 and up, you add an underscore after onMethod , onParam , or onConstructor . With Lombok. import lombok.AllArgsConstructor; import lombok.Getter;
Read more >
Lombok - the wrong way - SoftwareMill
A short story of what the Lombok library is and how to use it properly ... SnakeCaseStrategy.class) public class Job { public enum...
Read more >
How to Explore Project Lombok Using Java - NEX Softsys
In order to use Lombok in our maven project, simply include its dependency ... They as generated as per POJO convention and in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found