Issue
I migre my app to JDK11 (from JDK 8) so I up to springboot
2.2.4.RELEASE
and I add com.fasterxml.jackson.dataformat:jackson-dataformat-xml
my model:
@XmlRootElement(name = "dataModel")
public class DataModel {
...
}
my 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));
}
client:
curl -s --header "Accept: application/xml" http://localhost:8084/api/foo/columns
JDK8:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><dataModel><columns>author</columns><columns>zip</columns><columns>city</columns><columns>element</columns><columns>element2</columns><columns>date</columns><columns>title</columns></dataModel>
JDK11:
<DataModel><columns><columns>author</columns><columns>zip</columns><columns>city</columns><columns>element</columns><columns>element2</columns><columns>date</columns><columns>title</columns></columns></DataModel>
new result is strang:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><dataModel>
=> <DataModel>
<dataModel><columns>author</columns>...</dataModel>
=> <DataModel><columns><columns>author</columns>...</columns></DataModel>
I try add this dependencies but do not resolve:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.2</version>
</dependency>
Solution
remove this:
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
Answered By - Stéphane GRILLON
Answer Checked By - Mary Flores (JavaFixing Volunteer)