Content negotiation for XML response
See original GitHub issueGiven the example controller method shouldn’t XML be returned for the Firefox default Accept header "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
?
@RequestMapping(value = "/test", method = RequestMethod.GET)
public ResponseEntity<String[]> test(HttpServletRequest request) {
String[] result = {"value 1", "value 2", "value 3"};
return new ResponseEntity<String[]>(result, HttpStatus.OK);
}
The following URLs return a content type of “application/json;charset=UTF-8”:
But the URL “http://localhost:9000/test.xml” results in a “406 Not Acceptable”.
Setting the Accept header, using modify headers plugin, to only accept “application/xhtml+xml” for the URL “http://localhost:9000/test” also results in the same response.
Can someone explain what is happening?
Issue Analytics
- State:
- Created 10 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Spring Boot and Content Negotiation - XML and JSON ...
This guide will help you implement Content Negotiation for a REST API/Service with Spring Boot. Content Negotiation helps the Consumer and ...
Read more >Implement Content Negotiation using Spring Boot - JavaInUse
In this post we implement a simple Spring Boot example to implement Content Negotiation for returning XML or JSON depending upon the URL...
Read more >Content Negotiation Implementing Support for XML - Javatpoint
Content negotiation is the process of selecting the best representation for a given response when there are multiple representations available.
Read more >Content Negotiation using Spring MVC
When making a request via HTTP it is possible to specify what type of response you would like by setting the Accept header...
Read more >Spring MVC Content Negotiation - Baeldung
A guide to configuring content negotiation in a Spring MVC application and on enabling and disabling the various available strategies.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok. I was finally able to figure this out by extending ArrayList class and annotating it accordingly. Below is a solution for any others looking:
With Foos class defined as…
Thanks Dave!
Of course the solution works, but why is it needed? See comparison here: http://blog.codeleak.pl/2015/04/jax-rs-2x-vs-spring-mvc-returning-xml.html
Is there any better solution without wrapper?