Spring REST: HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' -


i getting above error, due problem jackson attempting deserialize pojo.

i've debugged code , returns false within jackson's objectmapper:

public boolean canread(type type, class<?> contextclass, mediatype mediatype) {     javatype javatype = getjavatype(type, contextclass);     return (this.objectmapper.candeserialize(javatype) && canread(mediatype)); } 

this.objectmapper.candeserialize(javatype) returns false causes error

my controller follows:

@controller public class cancelcontroller {     @autowired     private cancelservice cancelservice;      @requestmapping( value="/thing/cancel", method=requestmethod.post, consumes="application/json" )     public @responsebody cancelthingresponsedto cancelthing(@requestbody cancelrequestdto cancelthingrequest) {         return cancelservice.cancelthing(cancelthingrequest);     } 

my cancelrequestdto implements serializable:

public class cancelrequestdto implements serializable{   /**    * default serialization id    */   private static final long serialversionuid = 1l;   /**    * reason code associated request    */   private final string reasoncode;   /**    * identifier of entity associated request    */   private final entityidentifier entityidentifier;    /**    * default constructor    *    * @param reasoncode reason code associated request    * @param entityidentifier identifier of entity associated request    */   public cancelrequestdto(string reasoncode, entityidentifier entityidentifier) {     super();     this.reasoncode = reasoncode;     this.entityidentifier = entityidentifier;   }   /**    * @return returns reasoncode.    */   public string getreasoncode() {     return reasoncode;   }   /**    * @return returns entityidentifier.    */   public entityidentifier getentityidentifier() {     return entityidentifier;   } } 

my spring configuration follow:

<!-- dispatcherservlet context: defines servlet's request-processing     infrastructure -->  <!-- enables spring mvc @controller programming model --> <mvc:annotation-driven />  <!-- scan stereotype annotations --> <context:component-scan base-package="com.cancel.web.controller" />  <bean id="viewnametranslator"     class="org.springframework.web.servlet.view.defaultrequesttoviewnametranslator" />  <bean class="org.springframework.web.servlet.view.beannameviewresolver" />      <bean id="jsonview"     class="org.springframework.web.servlet.view.json.mappingjacksonjsonview" >     <property name="contenttype" value="application/json;charset=utf-8"/>     </bean>  <!-- register json converter restful web service --> <bean     class="org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter">     <property name="messageconverters">         <list>             <bean                 class="org.springframework.http.converter.json.mappingjacksonhttpmessageconverter">             </bean>         </list>     </property> </bean> 

anyone know might causing deserialization issue?

thanks

caused dto not having default constructor setters! looks inaccurate exception jackson


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -