jdereg / json-io

Convert Java to JSON. Convert JSON to Java. Pretty print JSON. Java JSON serializer. Deep copy Java object graphs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: how-to serialize Hibernate (proxy) objects

zetzet opened this issue · comments

I am currently searching for a JSON serializer that works with Hibernate Objects, that are partly initialized.
The current problem i face is a Hibernate LazyInitializationException, that a Hibernate PersistentSet will throw when json-io tries to serialize a collection that was not loaded by Hibernate.
I would like to skip the collection content serialization when PersistentSet.wasInitialized() returns true.
What is the right approach for this? I looked at the blacklist, but that doesn't really fit my problem.
Thanks for any hints, Jürgen

Serializers are going to read json and then assign the values at the field level, not calling hibernate methods to 'load' or 'fault-in' the objects. Can you traverse your hibernate object graph first. If you do that, then you should be able to serialize your hibernate objects.