Jackson 2.7.1 and Lombok: 'Conflicting/ambiguous property name definitions'
See original GitHub issue(move from https://github.com/FasterXML/jackson/issues/51 reported by @cnsgithub)
Hi,
Since I’ve updated to Jackson 2.7.1 mapping of some JSON strings to objects gives me this exception:
Exception in thread "main" java.lang.IllegalStateException: Conflicting/ambiguous property name definitions (implicit name 'foo'): found multiple explicit names: [bar, foo], but also implicit accessor: [method Ambiguity#getFoo(0 params)][visible=true,ignore=false,explicitName=false]
at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder._explode(POJOPropertyBuilder.java:913)
at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.explode(POJOPropertyBuilder.java:893)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._renameProperties(POJOPropertiesCollector.java:748)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:301)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getPropertyMap(POJOPropertiesCollector.java:248)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getProperties(POJOPropertiesCollector.java:155)
at com.fasterxml.jackson.databind.introspect.BasicBeanDescription._properties(BasicBeanDescription.java:142)
at com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findProperties(BasicBeanDescription.java:217)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._findCreatorsFromProperties(BasicDeserializerFactory.java:330)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._constructDefaultValueInstantiator(BasicDeserializerFactory.java:312)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findValueInstantiator(BasicDeserializerFactory.java:252)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:221)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:143)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:406)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:352)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
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:3889)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3784)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2779)
at TestAmbiguity.main(TestAmbiguity.java:12)
I just realized that the exception occurs only when used together with Lomboks @AllArgsConstructor annotation which adds a @ConstructorProperties annotation to the constructor…
JSON entity:
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
//not working
//@AllArgsConstructor
public class Ambiguity {
@JsonProperty("bar")
private int foo;
protected Ambiguity() {}
//not working (generated by lombok)
//@java.beans.ConstructorProperties(value = { "foo" })
//working
public Ambiguity(int foo) {
this.foo = foo;
}
public int getFoo() {
return foo;
}
@Override
public String toString() {
return "Ambiguity [foo=" + foo + "]";
}
}
Test:
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class TestAmbiguity {
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
String json = "{\"bar\":0}";
ObjectMapper mapper = new ObjectMapper();
System.out.println(mapper.readValue(json, Ambiguity.class));
}
}
Workaround to solve this are either switching back to Jackson 2.6.5 or not using Lombok annotation.
Issue Analytics
- State:
- Created 8 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Lombok and jackson - Conflicting/ambiguous property name ...
I get a WARN message: com.fasterxml.jackson.databind.JsonMappingException: Conflicting/ambiguous property name definitions (implicit name ' ...
Read more >都元ダイスケ on Twitter: "NowBrowsing: Jackson 2.7.1 and ...
NowBrowsing: Jackson 2.7.1 and Lombok: 'Conflicting/ambiguous property name definitions' · Issue #1122 · FasterXML…
Read more >MapperFeature (jackson-databind 2.8.5 API) - javadoc.io
Feature that can be enabled to make property names be overridden by wrapper name (usually detected with annotations as defined by AnnotationIntrospector.
Read more >com.fasterxml.jackson.databind.introspect ... - Tabnine
Method called to find out set of explicit names for accessors bound together due to implicit name. Popular methods of POJOPropertyBuilder. <init> ·...
Read more >Jackson Dependency Issue in Spring Boot with Maven Build
Jackson Databind has internal dependencies on Jackson Core and Annotation. Therefore, adding Jackson Databind to your Maven POM dependency list will include the ......
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
(from original issue)
Using project jackson-lombok (https://github.com/xebia/jackson-lombok) also works with Jackson 2.7.1, although it should be obsolete, it helps out in this case:
@cnsgithub within next couple of days.