Struts2 rest webservice with hibernate entity issue -
i doing webservice struts2 rest plugin, able send normal text , object json response, if try send hibernate entity having relationships not able send json response giving error
no serializer found class org.hibernate.proxy.pojo.javassist.javassistlazyinitializer , no properties discovered create beanserializer (to avoid exception, disable serializationconfig.feature.fail_on_empty_beans) ) (through reference chain: org.codehaus.jackson.map.jsonmappingexception["path"]->java.util.unmodifiablelist[0]->org.codehaus.jackson.map.reference["from"]->java.util.arraylist[0]->app.com.gmf.dto.restaurantmasterbean["restype"]->app.com.gmf.dto.restauranttypebean_$$_javassist_4["hibernatelazyinitializer"])
the error says : jsonmappingexception
the bean you're trying send contains other objects , not fetched eagerly & hence, there properties not initialized. when bean marshalled json, these properties fail. there multiple solutions :
- fetch eager (not recommended)
- send properties need , make sure they're fetched before returning action, otherwise might
lazyinitializationexception
wrapped withinjsonmappingexception
. said appears question,jackson
being used, can :
example :
@jsonignoreproperties({"restype"}) public class restaurantmasterbean{ private someotherobject restype; private string name; private boolean shouldinform; // getter , setters here... }
- simply ignore lazy fields :
@jsonignoreproperties({"hibernatelazyinitializer"})
Comments
Post a Comment