java - Spring Rest JSON Binding -


i'm trying create restful service spring.

a method accepts "usercontext" object via argument i.e. @requestbody.

the client sends json object content-type "application/json". error "http/1.1 415 unsupported media type".

..even when client sends null "{}" json object.

my controller:

@controller @requestmapping(value = "/entityservice") class restfulentityservice {    @resource   private entityservice entityservice;    @responsebody   @requestmapping(value = "/getlistofentities", method = requestmethod.post)   public list<entity> getlistofentities(@requestbody usercontext usercontext) {     system.out.println(usercontext);     return null;   } } 

usercontext.java

public class usercontext {      private long userid;      private string username;      private useraddress useraddress;      private customerinfo customerinfo;  } 

application context:

  <bean id="xstreammarshaller" class="org.springframework.oxm.xstream.xstreammarshaller"/>   <bean id="xmlmessageconverter"         class="org.springframework.http.converter.xml.marshallinghttpmessageconverter">     <constructor-arg ref="xstreammarshaller"/>     <property name="supportedmediatypes" value="application/xml"/>   </bean>    <bean id="jsonhttpmessageconverter"         class="org.springframework.http.converter.json.mappingjacksonhttpmessageconverter">     <property name="supportedmediatypes" value="application/json"/>   </bean>    <bean     class="org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter">     <property name="messageconverters">       <util:list id="beanlist">         <ref bean="xmlmessageconverter" />         <ref bean="jsonhttpmessageconverter"/>       </util:list>     </property>   </bean>    <mvc:annotation-driven/> 

struggling while. appreciated!

try accept header in request of application/json, based on see messageconverter samples @ mvc-showcase

this related question: use spring mvc3 @responsebody had 415 unsupported media type why?


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -