I'm using a Restful web service (Jersy implementation) with a JSF application and used Json to get the data as follows:
carObjectDao = new GenericDAO<carObject>(carObject.class);
List<carObject> allCars = carObjectDao.readAll();
Gson gson = new Gson();
String carString = gson.toJson(allCars);
System.err.println(carString );
return carString ;
i run the application in debug mode and allCars is filled with the data correctly, but after that an exception is thrown :
java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy. Forgot to register a type adapter?
i don't know the root cause of the exception
This is a known problem: Could not serialize object cause of HibernateProxy
JSon can't deserialize HibernateProxy objects, so you either unproxy or remove em.
Or, you can eager fetch the lazy data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With