Replies: 2 comments
-
|
Issue, belongs to jackson-databind, will convert. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Converted to issue #5765, closing discussion. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When upgrading from version 2 to 3 we encounter the following problem with @JsonUnwrapped, @JsonCreator and deserializing a JSON that does not contain all attributes specified in the Objects:
Having the following classes (for convenience of this post I used inner classes):
When using the ObjectMapper to deserialize JSON like in this test:
-> This works nicely!
-> This test fails with "expected: <SIGNAL_1-ID> but was: "
The difference between both tests is that the failing one does not specify the "unit" attribute.
The general thing is that if and only if not all attributes for the object which should be deserialized are given in the JSON, all attributes of the deserialized object with an @JsonUnwrapped annotation contain the default value (set in the default constructor) instead of the value defined in the JSON.
Expected:
Even if not all attributes of an object are specified in the JSON which is to be deserialized: The specified attributes are set in the objects created by the ObjectMapper.
Observed:
If not all attributes of an object are specified in the JSON which is to be deserialized: The specified attributes with an @JsonUnwrapped annotation contain the value set in the default constructor instead of the value defined in the JSON.
When debugging the code its obvious that for the failing case (not all attributes are given in the JSON) for all attributes annotated with @JsonUnwrapped first the @JsonCreator annotated constructor is called and afterwards the default constructor is called. BUT the setSignalId(String signalId) method is not called, therefore leaving the object initialized with the default value.
Looking around in the various forums it seems that the combined usage of @JsonUnwrapped and @JonCreator is discouraged.
Question: Is that the intended behaviour or is that a bug? How to handle this?
Her are the complete src files:
jackson-test.zip
Beta Was this translation helpful? Give feedback.
All reactions