-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Deserialization using @JsonCreator
with renamed property failing (since 2.18)
#4810
Comments
Please try 2.18.2. This issue sounds similar to issues that were fixed in that release. |
There is no 2.18.2? |
Try building latest 2.18 branch. That would be 2.18.2? |
I tried with the 2.18 and 2.19 branches, the issue is still here. |
Observations (tested without AutoValue, though):
|
I provided a simplified example. In real life, we don't really have any single-argument factory methods that could use this |
Eh sorry I meant |
I would strongly recommend against using plain |
@JsonCreator
with renamed property failing (since 2.18)
Ok, I can reproduce this, and the problem is that heuristics for mode detection only have access to properties before renaming, accessible only by implicit name. In 2.17 handling was done at a later point where access was post-renaming. I'll need to see if there is any way to be able to access explicit renaming. |
@cowtowncoder I gave a try to your patch, but the issue remains unchanged... 😕 This simpler example below, like the one you committed (but without the static class DataClass4810 {
private String x;
private DataClass4810(String x) {
this.x = x;
}
@JsonProperty("bar")
public String getFoo() {
return x;
}
@JsonCreator
public static DataClass4810 create(String bar) {
return new DataClass4810(bar);
}
}
@Test
void shouldSupportPropertyRenaming4810() throws Exception {
ObjectMapper mapper = JsonMapper.builder()
.addModule(new ParameterNamesModule())
.build();
JsonNode serializationResult = mapper.valueToTree(DataClass4810.create("42"));
assertEquals("{\"bar\":\"42\"}", serializationResult.toString());
DataClass4810 deserializationResult = mapper.treeToValue(serializationResult, DataClass4810.class);
assertEquals("42", deserializationResult.getFoo());
} What do you think? |
Should work - I tested with 2.18.2-SNAPSHOT (generated Give it another try? |
The fix went in @jmesny So how does your example differ from test I added? Test was failing before, passing after fix. It is possible there may be remaining edge case(s) but I'd need a reproduction. So I'd need to be able to reproduce remaining problems; can't do it yet. |
My attempt was made using a local build of the sources containing the patch. Thanks @cowtowncoder! |
@jmesny Just to be sure tho: now that 2.18.2 is released (last night), does the problem get resolved? If not, I would like to understand why; if yes, that's great. |
Yes, but I forgot to pass the required Sorry folks, everything works great with the 2.18.2 release! Thanks again @cowtowncoder |
@jmesny Ah! Yes, it's all good then -- thank you for confirmation |
Search before asking
Describe the bug
Hello,
Since v2.18, some of our data classes failed to be used for deserialization.
Those classes are making use of
@JsonProperty
et@JsonCreator
annotations, and rely on theParameterNamesModule
.Version Information
2.18.1
Reproduction
Example reproducing the issue:
Fails with the following error:
Expected behavior
We would expect that the
@JsonCreator
method parameter name be used to map the field having the same name in theJsonNode
.Additional context
Adding a
@JsonProperty("bar")
on the creator parameter solves the issue.The text was updated successfully, but these errors were encountered: