'Unsupported Media Type for application/xml even though I use MediaType.APPLICATION_XML_VALUE

I run the following curl command through postman.

curl --location --request POST 'http://localhost:8080/cefcy/get_eD_XML' \
--header 'Content-Type: application/xml' \
--header 'Cookie: JSESSIONID=800845E7C67023C8B0B3C8CF7B6EB0E4' \
--data-raw '<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:epsos="urn:epsos-org:ep:medication" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><typeId extension="POCD_HD000040" root="2.16.840.1.113883.1.3"/></ClinicalDocument>'

In my java spring boot project I have the following:

@SessionScope
@RestController
public class eD  extends Ctr  {
    private final static Logger LOG = LoggerFactory.getLogger(eD.class);

@RequestMapping(value = "/get_eD_XML", method=RequestMethod.POST,
        produces = {MediaType.APPLICATION_JSON_VALUE},consumes={MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE})
protected String eD_XML(@RequestBody ObjectNode model,HttpServletRequest request, 
        HttpServletResponse response) throws ServletException, IOException, NoSuchAlgorithmException {
    
    String eD = IOUtils.toString(request.getReader()); //trying to read the xml file
   }
}

However, in postman I get the following response:

{
    "timestamp": "2022-03-02T14:12:30.070+00:00",
    "status": 415,
    "error": "Unsupported Media Type",
    "message": "",
    "path": "/cefcy/get_eD_XML"
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source