Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy

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

like image 692
Eslam Mohamed Mohamed Avatar asked May 15 '13 22:05

Eslam Mohamed Mohamed


1 Answers

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.

like image 175
Ziul Avatar answered Oct 16 '22 05:10

Ziul