FasterXML / FasterXML/jackson-databind
`@JsonAnyGetter` can emit duplicate properties generating Invalid JSON
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 1.5k
- Avg merge
- 3d 6h
- Merged PRs (30d)
- 28
Description
This issue occurs when a key in the Map has the same name as a class member in the POJO. Find the test code below:
```
static class BeanWithProperty {
private String b;
final static Map extra = new HashMap();
static {
extra.put("a", Boolean.TRUE);
extra.put("b", Boolean.TRUE);
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
@JsonAnyGetter
public Map getExtra() {
return extra;
}
}
public void testAnyGetterWithDuplicateProperty() throws Exception {
String b = "false";
BeanWithProperty beanWithProperty = new BeanWithProperty();
beanWithProperty.setB("false");
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
String json = objectMapper.writeValueAsString(beanWithProperty);
BeanWithProperty beanWithProperty1 = objectMapper.readValue(json, BeanWithProperty.class);
// should not fail
assertEquals(beanWithProperty1.getB(), b);
}
```
**The test case fails**
I am observing same behavior in all the versions.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.