diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java b/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java index 66150240e4..d44457dd72 100644 --- a/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java +++ b/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java @@ -857,6 +857,11 @@ private void _explode(Collection newNames, for (Linked node = accessors; node != null; node = node.next) { PropertyName name = node.name; if (!node.isNameExplicit || name == null) { // no explicit name -- problem! + // [Issue#541] ... but only as long as it's visible + if (!node.isVisible) { + continue; + } + throw new IllegalStateException("Conflicting/ambiguous property name definitions (implicit name '" +_name+"'): found multiple explicit names: " +newNames+", but also implicit accessor: "+node); diff --git a/src/test/java/com/fasterxml/jackson/databind/introspect/TestPropertyConflicts.java b/src/test/java/com/fasterxml/jackson/databind/introspect/TestPropertyConflicts.java index 09be5d1b00..d8cec1d59d 100644 --- a/src/test/java/com/fasterxml/jackson/databind/introspect/TestPropertyConflicts.java +++ b/src/test/java/com/fasterxml/jackson/databind/introspect/TestPropertyConflicts.java @@ -1,6 +1,9 @@ package com.fasterxml.jackson.databind.introspect; +import com.fasterxml.jackson.annotation.*; + import com.fasterxml.jackson.core.JsonProcessingException; + import com.fasterxml.jackson.databind.*; /** @@ -62,6 +65,21 @@ public void _stuff(String value) { } } + // For [Issue#541] + static class Bean541 { + protected String str; + + @JsonCreator + public Bean541(@JsonProperty("str") String str) { + this.str = str; + } + + @JsonProperty("s") + public String getStr() { + return str; + } + } + /* /********************************************************** /* Test methods @@ -110,4 +128,23 @@ public void testInferredNameConflictsWithSetters() throws Exception Infernal inf = mapper.readValue(aposToQuotes("{'stuff':'Bob'}"), Infernal.class); assertNotNull(inf); } + + public void testIssue541() throws Exception { + final ObjectMapper mapper = new ObjectMapper(); + mapper.disable( + MapperFeature.AUTO_DETECT_CREATORS, + MapperFeature.AUTO_DETECT_FIELDS, + MapperFeature.AUTO_DETECT_GETTERS, + MapperFeature.AUTO_DETECT_IS_GETTERS, + MapperFeature.AUTO_DETECT_SETTERS, + MapperFeature.USE_GETTERS_AS_SETTERS + ); + Bean541 data = mapper.readValue("{\"str\":\"the string\"}", Bean541.class); + if (data == null) { + throw new IllegalStateException("data is null"); + } + if (!"the string".equals(data.getStr())) { + throw new IllegalStateException("bad value for data.str"); + } + } }