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 :

  1. fetch eager (not recommended)
  2. send properties need , make sure they're fetched before returning action, otherwise might lazyinitializationexception wrapped within jsonmappingexception. 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... } 
  1. simply ignore lazy fields :

@jsonignoreproperties({"hibernatelazyinitializer"})


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -