Created a spring boot rest service which accepts XML as a request and converts it into object and then inserts it into database. I used Jackson dataformat dependency for directly converting the xml request to object but getting an error .
The controller class is as follows
@RequestMapping(value = "/getRequestData",method=RequestMethod.POST,
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE},consumes={MediaType.APPLICATION_XML_VALUE})
public ResponseEntity<?> putDataIntoDatabase(@RequestBody FirstRequestorBean bean) {
logger.info(bean.getId());
return new ResponseEntity<String>(HttpStatus.OK);
}
and bean class
public class FirstRequestorBean {
private String name;
private String id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
the xml passed here is
<?xml version="1.0" encoding="UTF-8"?>
<FirstRequestorBean>
<name>Akhil</name>
<id>1</id>
</FirstRequestorBean>
getting a Unsupported Media Type exception.
can someone point out how to resolve the issue
<?xml version="1.0" encoding="UTF-8"?>and try addingMediaType.TEXT_XML.TEXT_XML(notice, notTEXT_XML_VALUE) and removing xml header?