Spring MVC 3.1与Jackson 2.0兼容吗?Spring MVC是否会在类路径上自动检测Jackson,并且使用JSON内容类型的请求委托给Jackson仍有效?
我正在尝试创建使用HTML的Web服务,该HTML随后用于与iText创建PDF。
我使用Postman来将请求发送到服务器,但是无论选择哪种内容类型,每次遇到以下错误时,我都可以使用:
{
"status": "CONFLICT",
"code": 40902,
"message": "Content type 'text/plain' not supported",
"developerMessage": "null",
"moreInfoUrl": "class org.springframework.web.HttpMediaTypeNotSupportedException",
"throwable": null
}
Run Code Online (Sandbox Code Playgroud)
消息根据所选内容类型而变化:
"message": "Content type 'text/xml' not supported"
"message": "Content type 'text/html' not supported"
Run Code Online (Sandbox Code Playgroud)
这是我的终点:
@RequestMapping(path = "/reports/pdf", method = RequestMethod.POST, consumes = MediaType.TEXT_HTML_VALUE)
public ResponseEntity<byte[]> generatePdfReport(@RequestBody String html) throws Exception {
byte[] pdfBytes = reportsService.generatePdf(html);
ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(pdfBytes, HttpStatus.OK);
return response;
}
Run Code Online (Sandbox Code Playgroud)
我已将consumes属性更改为:
MediaType.TEXT_PLAIN_VALUEMediaType.TEXT_XML_VALUE匹配我在Postman上发送的内容。
和@dnault注释一样,将其从RequestMapping注释中完全删除,结果相同。
我研究了类似的问题: