-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix #5342 @JsonAnyGetter
method serialization can override @JsonProperty
on name conflict
#5346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.19
Are you sure you want to change the base?
Conversation
@JsonProperty(value = "additionalProperties") | ||
private Map<String, Object> hidden; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified to hidden, so we get better view of what's actually conflicting --@JsonProperty(value = "additionalProperties")
@Test | ||
public void testPrivateAnyGetterSorted() throws Exception { | ||
PrivateAnyGetterPojoSorted pojo = new PrivateAnyGetterPojoSorted(); | ||
pojo.add("secondProperty", 2); | ||
String json = MAPPER.writeValueAsString(pojo); | ||
|
||
assertEquals(a2q("{" + | ||
"'firstProperty':1," + | ||
"'secondProperty':2," + // private accesor, wont' work here | ||
"'thirdProperty':3," + | ||
"'forthProperty':4}"), | ||
json); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I deleted so we have better visibility on subject matter)
@cowtowncoder May I ask for a bit of help on what the correct behavior should be?
So this one is now failing.
@JsonPropertyOrder
specified via line 131 does work now.
Now it serializes into...
{
"firstProperty":1,"
secondProperties":{"secondProperty":2}, // <---- as configured
"thirdProperty":3,
"forthProperty":4,
"secondProperty":2
}
... this, but I can't figure out why there is trailing "secondProperty":2
at the end.
Moreover, I am more confused because it the ordering like above should've worked even before since we have
public Map<String, Object> getSecondProperties() {
...
declared at line 133.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know for sure, but my guess is that the change broke linkage between
@JsonAnyGetter
private Map<String, Object> secondProperties = new HashMap<>();```
and
public Map<String, Object> getSecondProperties() {
return super.secondProperties;
so that "extra" one is for `@JsonAnyGetter` annotated field.
This whole set of tests and set up is very complicated and quite hard to reason about, unfortunately.
BeanPropertyWriter prop = props.get(i); | ||
// Either any-getter as field... | ||
if (Objects.equals(prop.getName(), anyGetter.getName()) | ||
if (Objects.equals(prop.getMember().getName(), anyGetter.getName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about this one: why is the change necessary/correct?
At least requires a comment on why we are looking at method/field name of concrete accessor, instead of processed property name.
No description provided.