Failure to find creator property with Lombok and an unwrapping mixin involved
See original GitHub issueThe following test case:
public class JacksonTest {
@Test
public void testname() throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new ParameterNamesModule());
mapper.addMixIn(Foo.class, FooMixin.class);
mapper.readValue("{ \"foo\" : \"something\", \"bar\" : \"something\" }", Foo.class);
}
@AllArgsConstructor
static class Foo {
String foo, bar;
Nested nested;
public Nested getNested() {
return nested;
}
}
@AllArgsConstructor
static class Nested {}
interface FooMixin {
@JsonUnwrapped
Nested getNested();
}
}
results in the following exception:
com.fasterxml.jackson.databind.JsonMappingException: Could not find creator property with name 'nested' (in class com.example.JacksonTest$Foo)
at [Source: { "foo" : "something", "bar" : "something" }; line: 1, column: 1]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:255)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:992)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:541)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:228)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:143)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:406)
The following things make it work and I kind of have a hard time understanding why š:
- Removing
@JsonUnwrappedfrom the mixin - Removing
getNested()from the mixin entirely - Not registering the mixin
- Adding
suppressConstructorProperties = trueto@AllArgsConstructoronFoo.
So it looks like that the āoverrideā of the accessor in the mixin has a higher priority than the constructor thatās generated by default Lombok. However, tricking Lombok into not adding the explicit constructor argument annotations seems to resolve the issue, too.
The error appears on 2.7.4, 2.6.5 works fine. Originally I thought I run into something related to #1122, but that one was resolved in 2.7.4.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:21 (11 by maintainers)
Top Results From Across the Web
Can't make Jackson and Lombok work together - Stack Overflow
The suppressConstructorProperties = true parameter tells Lombok not to add it (it does by default).
Read more >Untitled
Giovanni gasparini unicredit, Get current path java class, Dog cries owner dies, Batman earth 2 review, Kalender zu drucken 2013, Dr. simal patel,Ā ......
Read more >FasterXML - Bountysource
According to the documentation,. Annotation used to indicate that a property should be serialized "unwrapped"; that is, if it would be serialized as...
Read more >IntelliJ IDEA 2021.1 EAP (211.4961.27 build) Release Notes
Usability, IDEA-244923, IntelliJ no longer automatically activates a Maven profile using 'idea.version' system property. Code Analysis.
Read more >Spring Boot Reference Documentation
Loading YAML; Exposing YAML as Properties in the Spring Environment ... If your application fails to start, registered FailureAnalyzers get a chance toĀ ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top 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
Our team ran in to this issue today in a JDK8 project when upgrading from Spring Boot 1.5.1 to 1.5.2 (tons of dependency updates). After the upgrade, our controllers could not deserialize nested Lombok-annotated objects until a child objectās
@AllArgsConstructorannotation was updated withsuppressConstructorProperties = true.We ultimately created a
lombok.configfile in our project with this setting to fix the problem globally:Itās been hard for us to work through the above conversation and links to understand the context and the underlying issue. Is this an appropriate fix for the problem? Would there be any value in us creating an example project to share demonstrating the issue?
The example presented in my original post works on current Lombok generations as 1.16.20 changed its behavior to now not add the
@ConstructorPropertiesannotation by default anymore. However, if I configure it to add the annotation again (by settinglombok.anyConstructor.addConstructorProperties = trueinlombok.config) the exception still appears.In fact, this insāt even a Lombok issue at all. Iāve just removed Lombok and added
@ConstructorPropertiesmanually and the error appears:Removing
@ConstructorPropertiesmakes the test succeed. Iām using Jackson 2.9.6 these days. Stack trace is: