-
-
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
Unexpected deserialization behavior with @JsonCreator
, @JsonProperty
and javac -parameters
#4545
Comments
We also noticed that serialization behavior was different, without {
"key2" : "val2",
"key1" : "val1"
} with {
"key" : "val1",
"key2" : "val2"
} This can be reproduced with the following test: @Test
void test_serialization() throws JsonProcessingException {
Payload payload = new Payload("val1", "val2");
String jsonPayload = new ObjectMapper()
.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS) // deterministic output
.enable(SerializationFeature.INDENT_OUTPUT)
.findAndRegisterModules()
.writeValueAsString(payload);
Assertions.assertEquals("""
{
"key2" : "val2",
"key1" : "val1"
}""", jsonPayload);
} I have updated the following repository: https://github.com/ajacob/jackson-javac-parameters |
Quick note: change in serialization order is most likely due to Anyway: you may want to disable that setting. |
Should we start this issue over at parameter-names-module repo? |
I was hoping to create a reproduction on |
Ok, with #4515 work, this actually works as expected now: deserialization fails as expected. However: I noticed that there can be cases where it unexpectedly passes (withOUT parameter names module...). This is because of combination of |
Thank you for having a look and for detailed explanation |
Search before asking
Describe the bug
I found a behavior change when enabling the javac
-parameters
option on an existing java project.Not sure if this is a bug or intended, just sharing in case it can help others.
@JsonCreator
constructor, the value from a@JsonProperty
appears to be ignored for a parameter if a match exists between a json key name and the parameter name-parameters
(javac) andParameterNamesModule
module is registeredVersion Information
2.17.1
Reproduction
Have
jackson-module-parameter-names
as a dependency:Object used for deserialization:
Test:
This test pass, I find it a bit weird that the
@JsonProperty
value can be by-passed if the parameter name matches, but I guess this is a wanted/documented behavior.Now, compile the code with
-parameters
javac option:Without any code change, the test does not pass anymore because
key1
isnull
after deserialization.I have created a small project to reproduce this case: https://github.com/ajacob/jackson-javac-parameters
Expected behavior
We expected
key1
to benull
after deserialization when-parameters
is not enabled but may be this is a wanted behavior to have a fallback on the parameter name.We didn't expected a behavior change when
-parameters
option is enabled on javac withParameterNamesModule
enabled.In our case, we simply fixed the wrongly annotated parameters from the constructor to fix our issue
Additional context
No response
The text was updated successfully, but these errors were encountered: