json - Spring MVC with Jackson 2.2: "HttpMediaTypeNotAcceptableException: Could not find acceptable representation" -


so i'm struggling beans encoded in json... first tried codehaus' jackson 1.9.13 , spring mvc 3.1.1. had issues until managed "direct self-reference" exception. looking found needed fasterxml's jackson 2. found (here) need spring 3.1.2 because prior versions aren't supporting jackson 2.

so, after this... i'm still getting same exception. maven dependencies indeed including spring mvc 3.1.2 release jackson's 2 jars (and in build path)

<!-- jackson json -->     <dependency>         <groupid>com.fasterxml.jackson.core</groupid>         <artifactid>jackson-databind</artifactid>         <version>2.2.2</version>     </dependency>     <dependency>         <groupid>com.fasterxml.jackson.core</groupid>         <artifactid>jackson-annotations</artifactid>         <version>2.2.2</version>     </dependency>     <dependency>         <groupid>com.fasterxml.jackson.core</groupid>         <artifactid>jackson-core</artifactid>         <version>2.2.2</version>     </dependency> 

here controller method trying send bean:

@requestmapping(value = "/ws/{id}") public @responsebody resource displayws(@pathvariable final int id) {     return this.service.findbyid(id); } 

here receive in browser after call:

http status 406 resource identified request capable of generating responses characteristics not acceptable according request "accept" headers (). 

and here server log (jboss 7.1.1):

12:10:59,691 trace [org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod] (http-localhost-127.0.0.1-8080-1) error handling return value [type=com.steria.rm.model.internalresource] [value=luc mertens] handlermethod details:  controller [com.steria.rm.controller.resourcecontroller] method [public com.steria.rm.model.resource com.steria.rm.controller.resourcecontroller.displayws(int)] : org.springframework.web.httpmediatypenotacceptableexception: not find acceptable representation     @ org.springframework.web.servlet.mvc.method.annotation.abstractmessageconvertermethodprocessor.writewithmessageconverters(abstractmessageconvertermethodprocessor.java:147) [spring-webmvc-3.1.2.release.jar:3.1.2.release]     @ org.springframework.web.servlet.mvc.method.annotation.abstractmessageconvertermethodprocessor.writewithmessageconverters(abstractmessageconvertermethodprocessor.java:80) [spring-webmvc-3.1.2.release.jar:3.1.2.release]     @ org.springframework.web.servlet.mvc.method.annotation.requestresponsebodymethodprocessor.handlereturnvalue(requestresponsebodymethodprocessor.java:94) [spring-webmvc-3.1.2.release.jar:3.1.2.release]     @ org.springframework.web.method.support.handlermethodreturnvaluehandlercomposite.handlereturnvalue(handlermethodreturnvaluehandlercomposite.java:74) [spring-web-3.1.2.release.jar:3.1.2.release]     @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:110) [spring-webmvc-3.1.2.release.jar:3.1.2.release]     @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlermethod(requestmappinghandleradapter.java:617) [spring-webmvc-3.1.2.release.jar:3.1.2.release]     @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:578) [spring-webmvc-3.1.2.release.jar:3.1.2.release]     @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:80) [spring-webmvc-3.1.2.release.jar:3.1.2.release]     @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:923) [spring-webmvc-3.1.2.release.jar:3.1.2.release]     @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:852) [spring-webmvc-3.1.2.release.jar:3.1.2.release]     @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:882) [spring-webmvc-3.1.2.release.jar:3.1.2.release]     @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:778) [spring-webmvc-3.1.2.release.jar:3.1.2.release]     @ javax.servlet.http.httpservlet.service(httpservlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.final.jar:1.0.0.final]     @ javax.servlet.http.httpservlet.service(httpservlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.final.jar:1.0.0.final]     @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:329) [jbossweb-7.0.13.final.jar:]     @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:248) [jbossweb-7.0.13.final.jar:]     @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:275) [jbossweb-7.0.13.final.jar:]     @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:161) [jbossweb-7.0.13.final.jar:]     @ org.jboss.as.jpa.interceptor.webnontxemcloservalve.invoke(webnontxemcloservalve.java:50) [jboss-as-jpa-7.1.1.final.jar:7.1.1.final]     @ org.jboss.as.web.security.securitycontextassociationvalve.invoke(securitycontextassociationvalve.java:153) [jboss-as-web-7.1.1.final.jar:7.1.1.final]     @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:155) [jbossweb-7.0.13.final.jar:]     @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:102) [jbossweb-7.0.13.final.jar:]     @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109) [jbossweb-7.0.13.final.jar:]     @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:368) [jbossweb-7.0.13.final.jar:]     @ org.apache.coyote.http11.http11processor.process(http11processor.java:877) [jbossweb-7.0.13.final.jar:]     @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:671) [jbossweb-7.0.13.final.jar:]     @ org.apache.tomcat.util.net.jioendpoint$worker.run(jioendpoint.java:930) [jbossweb-7.0.13.final.jar:]     @ java.lang.thread.run(unknown source) [rt.jar:1.7.0_21] 

ps: internalresource child of resource.

so now, going on ? i've seen somewhere exception might thrown reason not one... kind of swallowing , throwing "high level" exception... not sure if it's true tho.

i've tried headers = "accept=*/*", produces = "application/json"... 1 @ time, both together, still not working...

any idea guys?
ps: know there many similar posts if not i've seen prior 2012 year of jackson's 2 release (may)

alright, figured out.

first, suspected, spring mvc wasn't calling jackson serialize entities. found here, needed modify mvc:annotation-driven to

<mvc:annotation-driven>     <mvc:message-converters register-defaults="false">         <bean id="jacksonmessageconverter" class="org.springframework.http.converter.json.mappingjackson2httpmessageconverter"/>     </mvc:message-converters> </mvc:annotation-driven> 

after done, direct self-reference exception... after looked hour, found 'simply' needed add annotation classes.

@jsonidentityinfo(generator=objectidgenerators.intsequencegenerator.class, property="@id") 

this annotation means if object repeated while in serializer serialized once after referenced @id created serializer.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -