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

纵然是瞬间 提交于 2019-12-21 05:06:33

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/16576009/java-lang-unsupportedoperationexception-attempted-to-serialize-java-lang-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!