Lazy associations mapped as null values even if JsonInclude.NON_NULL is present
This module rocks! But I think we are missing a feature to actually not include the association at all in the response. I have the module setup and my mapper is using mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
But all the lazy associations are displayed in my json as null values. The other nulls I have (single table columns) are not serialized but the associations are displayed.
This is tricky one unfortunately; the problem being that handling of null values occurs by the serializer itself; which is unfortunately too late for null suppression. And conversely caller does not know that value should be treated as null.
Is it possible to add a new Feature in HibernateModule that overrides the writing of null and does not write the lazy associations?
That is not easy, since each individual serializer would need to handle null suppression or masking, so there is no general facility for doing that. It might be easier for just suppressing lazy references.
But in general what would help most is finding active developers for this module -- I try to help, but I don't use Hibernate myself, so I don't have as much itch as others would.
+1
+1
Code contributions are most welcome!
It would be very nice if we had a unit test to reproduce this -- perhaps something based on a real project. Fixing might be easy.
One other comment: instead of using NON_NULL, one that is more likely to work is NON_EMPTY -- it will be easier to make work due to way proxies are handled.
I added proper handling of @JsonInclude(Include.NON_EMPTY) for lazy-loaded collections; whether same can be made to work for NON_NULL is unclear because physical property value is not null ever (there is a proxy for handling lazy-loading).
So I would strongly recommend using Include.NON_EMPTY setting instead.
+1
Hi guys, I am interested in this issue. Is somebody working on this? I can provide a real example to reproduce the issue.
@mmonti I don't think anyone is working on this. A reproduction would be helpful; especially if it demonstrates the issue on Jackson 2.7.
@cowtowncoder I put together an example of the issue #21 in this project: https://github.com/mmonti/entity-graph
There is just one test: ApplicationTests.testIdentityLazyManyToMany() which is self explanatory. The hibernate module is configured in the class WebConfig.java
Let me know if you have any questions about the example and also how can I help with this.
Does this issue still exist? Its really critical because directly affects client side, Any new news?
It's working very well (removing null/empty fields), please close the issue.
mapper.serializationInclusion(JsonInclude.Include.NON_EMPTY);
Hibernate: 5.2.16.Final Jackson: 2.5.9 Jackson-datatype-hibernate5: 2.9.5
@n0ise9914 It's about JsonInclude.NON_NULL, so the issue is still present. Not everyone wants to switch to Include.NON_EMPTY, as this is a different option.
this is still a (big) problem because it does not work on version 2.9.8 Any body working on that ?