i’m using hibernate to lazily retrieve content from a database.
This content is then serialised to json output, the problem is that jackson invoke getters on the “persistentBag” i get from hibernate, ending with a “no session or session was closed” exception.
In fact i would like to tell jackson “if a list is not loaded (means if it’s a persistentBag) then don’t serialise it”
What is the best way to achieve this ? Any jackson config to excluse persistentBag from serialisation ?
Should i use reflect api to set persistentBag to new empty list ?
What’s the best ? Thank you and happy new year guys !
You could try to use
@JsonIgnoreto entirely ignore the marked property. Annotation wise I don’t think there is a “if lodaded” option.What you could of course do is to write your own marshaller that checks the type and decides how to proceed.
I have e.g. written a serializer for a custom data type
Which is then used to serialize that type by adding some annotations:
That custom serializer gives you full control, but is of course a bit more work to implement than just a simple annotation.