java - convert hibernate model into json spring mvc reponsebody -


everyone.

i'm trying convert hibernate pojo json responsebody this:

  @requestmapping(value = "/getadicionalesbycumplimiento/{idcumplimiento}", method = requestmethod.get)     public @responsebody     list<adicional> getadicionalesbycumplimiento(httpsession session,             @pathvariable(value = "idcumplimiento") long idcumplimiento) {         usuario usuario = (usuario) session.getattribute("usuarioobject");         if (usuario != null) {             cumplimientos cumplimientos = cumplimientodao.getcumplimientobyid(idcumplimiento);             list<adicional> adicionales = adicionaldao.getadicionalesbycumplimiento(cumplimientos);             return adicionales;         } else {             return null;         }     } 

i added @jsonignoreproperties({"hibernatelazyinitializer", "handler"}) every single pojo in application, in order ignore lazy fetched attributes, set every single relationship attribute not real solution, turns code difficult maintain.

this stack trace:

30-sep-2015 10:35:25.457 severe [http-nio-8080-exec-53] org.apache.catalina.core.standardwrappervalve.invoke el servlet.service() para el servlet [dispatcher] en el contexto con ruta [/gestiontransporte] lanzó la excepción [request processing failed; nested exception java.lang.unsupportedoperationexception: attempted serialize java.lang.class: org.hibernate.proxy.hibernateproxy. forgot register type adapter?] con causa raíz  java.lang.unsupportedoperationexception: attempted serialize java.lang.class: org.hibernate.proxy.hibernateproxy. forgot register type adapter?     @ com.google.gson.internal.bind.typeadapters$1.write(typeadapters.java:67)     @ com.google.gson.internal.bind.typeadapters$1.write(typeadapters.java:61)     @ com.google.gson.internal.bind.typeadapterruntimetypewrapper.write(typeadapterruntimetypewrapper.java:68)     @ com.google.gson.internal.bind.arraytypeadapter.write(arraytypeadapter.java:93)     @ com.google.gson.internal.bind.typeadapterruntimetypewrapper.write(typeadapterruntimetypewrapper.java:68)     @ com.google.gson.internal.bind.reflectivetypeadapterfactory$1.write(reflectivetypeadapterfactory.java:99)     @ com.google.gson.internal.bind.reflectivetypeadapterfactory$adapter.write(reflectivetypeadapterfactory.java:219)     @ com.google.gson.internal.bind.typeadapterruntimetypewrapper.write(typeadapterruntimetypewrapper.java:68)     @ com.google.gson.internal.bind.reflectivetypeadapterfactory$1.write(reflectivetypeadapterfactory.java:99)     @ com.google.gson.internal.bind.reflectivetypeadapterfactory$adapter.write(reflectivetypeadapterfactory.java:219)     @ com.google.gson.internal.bind.typeadapterruntimetypewrapper.write(typeadapterruntimetypewrapper.java:68)     @ com.google.gson.internal.bind.reflectivetypeadapterfactory$1.write(reflectivetypeadapterfactory.java:99)     @ com.google.gson.internal.bind.reflectivetypeadapterfactory$adapter.write(reflectivetypeadapterfactory.java:219)     @ com.google.gson.internal.bind.typeadapterruntimetypewrapper.write(typeadapterruntimetypewrapper.java:68)     @ com.google.gson.internal.bind.reflectivetypeadapterfactory$1.write(reflectivetypeadapterfactory.java:99)     @ com.google.gson.internal.bind.reflectivetypeadapterfactory$adapter.write(reflectivetypeadapterfactory.java:219)     @ com.google.gson.internal.bind.objecttypeadapter.write(objecttypeadapter.java:107)     @ com.google.gson.internal.bind.typeadapterruntimetypewrapper.write(typeadapterruntimetypewrapper.java:68)     @ com.google.gson.internal.bind.collectiontypeadapterfactory$adapter.write(collectiontypeadapterfactory.java:96)     @ com.google.gson.internal.bind.collectiontypeadapterfactory$adapter.write(collectiontypeadapterfactory.java:60)     @ com.google.gson.gson.tojson(gson.java:600)     @ com.google.gson.gson.tojson(gson.java:579)     @ com.google.gson.gson.tojson(gson.java:554)     @ org.springframework.http.converter.json.gsonhttpmessageconverter.writeinternal(gsonhttpmessageconverter.java:204)     @ org.springframework.http.converter.abstracthttpmessageconverter.write(abstracthttpmessageconverter.java:208)     @ org.springframework.web.servlet.mvc.method.annotation.abstractmessageconvertermethodprocessor.writewithmessageconverters(abstractmessageconvertermethodprocessor.java:161)     @ org.springframework.web.servlet.mvc.method.annotation.abstractmessageconvertermethodprocessor.writewithmessageconverters(abstractmessageconvertermethodprocessor.java:101)     @ org.springframework.web.servlet.mvc.method.annotation.requestresponsebodymethodprocessor.handlereturnvalue(requestresponsebodymethodprocessor.java:167)     @ org.springframework.web.method.support.handlermethodreturnvaluehandlercomposite.handlereturnvalue(handlermethodreturnvaluehandlercomposite.java:71)     @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:126)     @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:777)     @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:706)     @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85)     @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:943)     @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:877)     @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:966)     @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:857)     @ javax.servlet.http.httpservlet.service(httpservlet.java:622)     @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:842)     @ javax.servlet.http.httpservlet.service(httpservlet.java:729)     @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291)     @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206)     @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52)     @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239)     @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206)     @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88)     @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107)     @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239)     @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206)     @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:219)     @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:106)     @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:502)     @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:142)     @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79)     @ org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:617)     @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88)     @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:518)     @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1091)     @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:668)     @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1527)     @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1484)     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142)     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617)     @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61)     @ java.lang.thread.run(thread.java:745) 

i found answer, put @jsonidentityinfo(generator = objectidgenerators.propertygenerator.class, property = "idadicional") annotation in every single pojo , worked


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -