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

sgrillon :

I want to move my Spring-Boot project from JDK 8 to 11.

Controller :

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

My JSON curl (OK in JDK 8 and JDK 11):

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

My XML curl (OK in JDK 8 but not OK in JDK 11):

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

In JDK 11, the result is coming empty.

How to resolve this (I need use my code on JDK8 and JDK11)?

EDIT:

I have this error:

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

Try the higher version of Jackson for XML support.

Add this dependency in pom.xml.

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

springboot 2.1.6.RELEASE call jackson-dataformat-xml 2.9.9 only, if you up to 2.10.1, it solves the issue.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=10182&siteId=1