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.

Failure to find creator property with Lombok and an unwrapping mixin involved

See original GitHub issue

The 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 @JsonUnwrapped from the mixin
  • Removing getNested() from the mixin entirely
  • Not registering the mixin
  • Adding suppressConstructorProperties = true to @AllArgsConstructor on Foo.

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:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

7reactions
lnhrdtcommented, Mar 6, 2017

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 @AllArgsConstructor annotation was updated with suppressConstructorProperties = true.

We ultimately created a lombok.config file in our project with this setting to fix the problem globally:

lombok.anyConstructor.suppressConstructorProperties = true

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?

3reactions
odrotbohmcommented, Aug 7, 2018

The example presented in my original post works on current Lombok generations as 1.16.20 changed its behavior to now not add the @ConstructorProperties annotation by default anymore. However, if I configure it to add the annotation again (by setting lombok.anyConstructor.addConstructorProperties = true in lombok.config) the exception still appears.

In fact, this ins’t even a Lombok issue at all. I’ve just removed Lombok and added @ConstructorProperties manually and the error appears:

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);
	}

	static class Foo {

		String foo, bar;
		Nested nested;

		@ConstructorProperties({ "foo", "bar", "nested" })
		public Foo(String foo, String bar, Nested nested) {}

		public Nested getNested() {
			return nested;
		}
	}

	@AllArgsConstructor
	static class Nested {}

	interface FooMixin {

		@JsonUnwrapped
		Nested getNested();
	}
}

Removing @ConstructorProperties makes the test succeed. I’m using Jackson 2.9.6 these days. Stack trace is:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot define Creator property "nested" as `@JsonUnwrapped`: combination not yet supported
 at [Source: (String)"{ "foo" : "something", "bar" : "something" }"; line: 1, column: 1]
	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
	at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1451)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase._findPropertyUnwrapper(BeanDeserializerBase.java:836)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:494)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:293)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
	at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
	at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:477)
	at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:4190)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4009)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3004)
	at JacksonTest.testname(JacksonTest.java:20)
	…
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

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