Skip to content
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

Incorrect deserialization of inner object when using @JsonUnwrapped, with duplicate property #1176

Open
Sild opened this issue Mar 30, 2016 · 6 comments

Comments

@Sild
Copy link

Sild commented Mar 30, 2016

I suggest that there is a bug, if I define the same names for getters\setters name in Child and Root classes.
I have try to use @JsonIgnore on Root getters\setters to prevent double-serialize, but always get null in child object.

Example of my issue: https://github.com/Sild/jackson-deserialize-test/

We get null in Child.entity. But if we rename Root.getEntity() and Root.setEntity() method (to getChildEntity, for example), we get correct Child.entity value

@Sild Sild changed the title Deserialize internal object by using @JsonUnwrapped Incorrect Deserializing of internal object by using @JsonUnwrapped Mar 30, 2016
@cowtowncoder
Copy link
Member

What would the expected behavior here be, in case of duplicates?

@Sild
Copy link
Author

Sild commented Mar 30, 2016

I have tried to mark Root.getEntity() and Root.setEntity() as @JsonIgnor to prevent duplicates and it helped on serialize, so I expect to skip it on deserialize.

@cowtowncoder
Copy link
Member

@Sild So you would expect child property entity to mask property entity that parent has. But while that works on serialization, when deserializing ignoral also applies to Child where it should not?
If so, yes, I agree, this is not optimal.

I just wanted to verify that I understand expected behavior correctly, thank you for clarification.

@Sild
Copy link
Author

Sild commented Mar 30, 2016

@cowtowncoder Yes,

But while that works on serialization, when deserializing ignoral also applies to Child where it should not?

That's exactly what I want.

One more, Parent has no property entity. But has methods getEntity() and setEntity() with the same name as Child to provide access to Child's property entity.

@cowtowncoder
Copy link
Member

@Sild by having methods getEntity() and setEntity(), parent object does indeed have property "entity" -- whether there is a field with that name or not is irrelevant from property introspection perspective. Fields are not same as properties, although existence of a visible field does also indicate a property: but property is a logical concept.

@Sild
Copy link
Author

Sild commented Apr 7, 2016

@cowtowncoder Thanks for your explanation. Then let's focus on @JsonIgnore annotation in Parent object and its expected behaviour during serialize\deserialize.

@cowtowncoder cowtowncoder changed the title Incorrect Deserializing of internal object by using @JsonUnwrapped Incorrect deserialization of inner object when using @JsonUnwrapped, with duplicate property May 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants