-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Attributes and nested de-serialization #3000
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
Comments
Ok there are two different parts to the problem. Starting with changing ObjectMapper mapper = new ObjectMapper();
mapper.setConfig(mapper.getDeserializationConfig().withAttribute("message", "test")); Now: second part wrt
will go to The proper solution actually would be not to use if (bar != null) {
// .traverse() will create JsonParser: not 100% if "parser.nextToken()" needs to be called before
// using here:
foo.bar = ctx.readValue(bar.traverse(), Bar.class);
} but that would fully retain appropriate So: I would recommend changing deserialization like this and then you can decide whether to set default attributes for |
One other minor improvement suggestion: |
I hope above helps solving the issue: there isn't much databind can do (in 2.x -- 3.0 actually does have improvements that will keep attributes via |
In a deserializer I'm writing I need to access to some attributes but it looks like those attributes are not propagated to nested deserializations.
For demonstration purpose I have created the following two classes:
If I deserialize
Foo
setting the attributes to the deserialization config, like:At this point, neither
Foo
norBar
have themessage
field set with themessage
attribute.If instead I set the attributes on the reader, like:
Then
Foo
has the expected message set whereasBar
not.I'm pretty sure I'm doing something wrong but I have not found a relevant documentation about how to properly sue attributes so any help would be really appreciated.
The text was updated successfully, but these errors were encountered: