Affects: 6.0.4
During the analysis of https://github.com/spring-projects/spring-framework/issues/29588 it was discovered that the XML version of Problem Details document is invalid (per RFC 7807).
curl -H "Accept: application/problem+xml, application/xml" -i http://localhost:8080/foo
HTTP/1.1 404
Content-Type: application/problem+xml
Transfer-Encoding: chunked
Date: Fri, 03 Feb 2023 21:16:53 GMT
<ProblemDetail><type>about:blank</type><title>Not Found</title><status>404</status><detail>No endpoint GET /foo.</detail><instance>/foo</instance></ProblemDetail>
The root node has to be <problem xmlns="urn:ietf:rfc:7807">
per Appendix A of RFC 7807. Also a <?xml version="1.0" encoding="UTF-8"?>
header is prepended in the RFC example.
For the sake of compleness, this is my applicaton.properties
:
spring.mvc.problemdetails.enabled=true
spring.mvc.throw-exception-if-no-handler-found=true
spring.web.resources.add-mappings=false
The Java code is pretty uninteresting as this example requests a non-existing resource (404) anyway.
Comment From: rstoyanchev
I don't know if you tried this with Java 8 which includes JAXB? We cannot add JAXB annotations directly on ProblemDetail
since JAXB is no longer included in later versions of the JDK.
However, we can add @JsonRootName
on ProblemDetailJacksonMixin
and that will allow correct rendering with the Jackson XML extension.
Comment From: osiegmar
I don't know if you tried this with Java 8 which includes JAXB?
I tested it with Java 17. Isn't Java >= 17 required by Spring 6? ;-)
Comment From: rstoyanchev
Yes, it is and this is why we can't put JAXB annotations ProblemDetail
. I'm guessing then the output was written with MappingJackson2XmlHttpMessageConverter
.