Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ProblemDetail serialization to XML with Jackson #29927

Closed
osiegmar opened this issue Feb 3, 2023 · 3 comments
Closed

Support ProblemDetail serialization to XML with Jackson #29927

osiegmar opened this issue Feb 3, 2023 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@osiegmar
Copy link

osiegmar commented Feb 3, 2023

Affects: 6.0.4

During the analysis of #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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 3, 2023
@rstoyanchev rstoyanchev self-assigned this Feb 7, 2023
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 7, 2023
@rstoyanchev rstoyanchev added this to the 6.0.5 milestone Feb 7, 2023
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Feb 7, 2023

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.

@osiegmar
Copy link
Author

osiegmar commented Feb 7, 2023

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? ;-)

@rstoyanchev
Copy link
Contributor

Yes, it is and this is why we can't put JAXB annotations ProblemDetail. I'm guessing then the output was written with MappingJackson2XmlHttpMessageConverter.

@rstoyanchev rstoyanchev changed the title XML version of Problem Details document is invalid Support ProblemDetail serialization to XML with Jackson Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants