I'm having trouble displaying a JSON Post message on a specific Java object to save it using Hibernate
Ajax call headers set correctly ...
Accept application/json Content-Type application/json; charset=UTF-8
and the HTTP POST method
Here is my configuration ...
My Spring MVC function mapping is as follows:
@RequestMapping(value = {"/save.json"},method = RequestMethod.POST) public ModelMap save(@RequestBody Seizure seizureObj,Model model) { ... }
in my xml container I have a ContentNegotiationViewResolver like this
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="mediaTypes"> <map> <entry key="html" value="text/html" /> <entry key="json" value="application/json" /> </map> </property> <property name="viewResolvers"> <list> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/assets/" /> <property name="suffix" value=".jsp" /> </bean> </list> </property> <property name="defaultViews"> <list> <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"> <property name="prefixJson" value="false" /> <property name="objectMapper" ref="jacksonObjectMapper" /> </bean> </list> </property> </bean>
in my container xml part for jackson
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapterConfigurer" init-method="init"> <property name="messageConverters"> <list> <bean id="marshallingHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" > <property name="objectMapper" ref="jacksonObjectMapper" /> </bean> </list> </property> </bean> <bean id="jacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper" />
I have
- JACKSON-core-ASL-1.8.5
- JACKSON-Mapper-ASL-1.8.5
in the / lib folder
and Jackson works for a simple case like this
public class Simple { private int id; public int getId() { return id; } public void setId(int id) { this.id = id; } } @RequestMapping(value = {"/saveSimple.json"},method = RequestMethod.POST) public ModelMap save(@RequestBody Simple simple,Model model) { ... }
when i test it with curl
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":1}' http:
No problem, but if I test it with a Hibernate object, I get a message
415 Unsupported Media Type
any ideas.