`SNAKE_CASE` doesn't work when using Lombok's `@AllArgsConstructor`
See original GitHub issueSNAKE_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:
- Created 7 years ago
- Comments:18 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.If you need any testing, feel free to ping me. It was merely chance that I stumbled upon this.