为什么 header "Accept: application/xml" 在移动到 Java 11 后在 Spring 引导中不起作用?

Why the header "Accept: application/xml" does not work in Spring Boot after moving to Java 11?

我想将我的 Spring-Boot 项目从 JDK 8 移动到 11。

控制器:

    @RequestMapping(value = "/{model}/columns", method = RequestMethod.GET, consumes = MediaType.ALL_VALUE, produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE })
    public ResponseEntity<DataModel> getColumnsModel(@PathVariable String model) {
        LOGGER.info("getColumnsModel : model[{}]", model);
        DataModel dataModel = modelService.getColumns(model);
        return Optional.ofNullable(dataModel).map(result -> new ResponseEntity<>(result, HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NO_CONTENT));
    }

我的 JSON curl(在 JDK 8 和 JDK 11 中正常):

curl -s --header "Accept: application/json" http://localhost:8084/noraui/api/hello/columns > target/actual_hello_columns.json

我的 XML curl(在 JDK 8 中正常,但 在 JDK 11 中不正常):

curl -s --header "Accept: application/xml" http://localhost:8084/noraui/api/hello/columns > target/actual_hello_columns.xml

在JDK11,结果是空的。

如何解决这个问题(我需要在 JDK8 和 JDK11 上使用我的代码)?

编辑:

我有这个错误:

Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]

尝试使用更高版本的 Jackson 以获得 XML 支持。

pom.xml中添加这个依赖。

<dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
    <version>2.10.1</version>
</dependency>

spring-boot 2.1.6.RELEASE 只调用 jackson-dataformat-xml 2.9.9,如果你达到 2.10.1,它就解决了问题。