application/xml 不支持媒体类型,即使我使用 MediaType.APPLICATION_XML_VALUE

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

我运行下面的curl命令通过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>'

在我的 java spring 引导项目中,我有以下内容:

@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
   }
}

但是,在邮递员中我得到以下回复:

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

感谢 MI's blog pom.xml.

中需要以下依赖项
<dependency>
  <groupId>com.fasterxml.jackson.dataformat</groupId>
  <artifactId>jackson-dataformat-xml</artifactId>
  <version>2.11.0</version>
</dependency>