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 serialization of Lazy objects #77

Open
EddieJamsession opened this issue Oct 18, 2015 · 7 comments
Open

Incorrect serialization of Lazy objects #77

EddieJamsession opened this issue Oct 18, 2015 · 7 comments

Comments

@EddieJamsession
Copy link

More you can find here:

http://stackoverflow.com/questions/33194554/two-different-resulting-jsons-when-serializing-lazy-objects-and-simple-objects

Guys, I've already find out, what's the problem and solved it with hack,
when we try to serialize Hibernate proxy, and isUnwrappingSerializer() is being called, the HibernateProxySerializer is always returning false as per parent class.

But it should return the same answer that the actual serializer of the proxied value object is returning.
And now we have problem that unwrapping instructions are just ignored.

@cowtowncoder
Copy link
Member

At this point, a unit test would be needed.

@cowtowncoder
Copy link
Member

I don't doubt there is an issue here; but a full reproduction would be useful to do proper fix. Problem is probably bigger than just relaying of isUnwrappingSerializer(), as there should also be delegation for other methods, and it would be great to fix other issues that stem from this.

@alanhay
Copy link

alanhay commented Feb 22, 2017

For information and as the original SO question has been deleted,I have encountered the same issue as reported here:

http://stackoverflow.com/questions/42395831/issue-serializing-lazy-manytoone

Any workround? If any further information would be useful please advise.

@shakuzen
Copy link

shakuzen commented Apr 3, 2017

I don't know if my situation is exactly the same as the other two people reporting here, but I am noticing the same thing. I have made a repository that reproduces the issue in a JUnit test: https://github.com/shakuzen/jackson-hibernate-serialization-repro

@cowtowncoder I have done a lot of debugging to understand what is going on here (at least in my case). Spring Data REST's PersistentEntityJackson2Module$NestedEntitySerializer will wrap entities in a org.springframework.hateoas.Resource object. When the entity is actually a HibernateProxy, serialization will be performed by this module's HibernateProxySerializer, but since it is not an UnwrappingSerializer, the Resource's content field name will be serialized whereas it is expected to be unwrapped since it is marked with @JsonUnwrapped. This is why the result has a content field that does not belong, with the expected entity as its value.

I'm not sure exactly what should be changed in what way, which is why I didn't just open a pull request, but let me know if I can help with anything.

@sullrich84
Copy link

Any updates on this issue?

@sdwarwick
Copy link

Although this appears to be an old problem, it has far-reaching implications for system optimization. In cases where @Entities are being used both to specify database and JSON serialization strategies, it is not possible to optimize fetching strategies in JPA/Hibernate in production without impacting serialization since @JsonUnwrapped is not respected by this module. In our case, we have close to 100 JSON/XML Spring @Responsebody endpoints that will be impacted by moving to lazy fetch - either by unintentionally restructuring the JSON response or failing due to the lazy load issue.

@angheladrian
Copy link

We have the same problem. Any updates or plans?

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

7 participants