I'm trying to write a simple web service that automagically serializes and deserializes objects using JAXB:
@XmlRootElement
public class SimpleObject {
private int id;
private String name;
/* ... */
}
@Controller
public class SimpleObjectController {
@RequestMapping("submit",method=RequestMethod.POST)
public String doPost(@RequestBody SimpleObject value) {
return value.toString();
}
}
<?xml version="1.0"?>
<beans ...>
<oxm:jaxb2-marshaller id="marshaller" class="path.to.objects"/>
</beans>
When I actually make the request, however, I get the following:
HTTP Status 415
The server refused this request because the request entity is in a format not
supported by the requested resource for the requested method ().
I get no logs back from Spring, making it hard for me to determine the root cause. Is there a critical step in this process which I'm missing?
Typically this is because of a missing Accept header or Content Type header of "application/xml" in your request. Also if you are using Spring 3.1, you can make your annotation even more explicit this way:
@RequestMapping(value="submit",method=RequestMethod.POST, consumes="application/xml", produces="application/xml")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.