Spring 3.x JSON status 406 "characteristics not acceptable according to the request "accept" headers ()" - Stack Overflow
53 captures
15 Jan 2013 - 11 Jul 2024
Sep
OCT
Nov
11
2015
2016
2017
success
fail
About this capture
COLLECTED BY
Organization:
Internet Archive
These crawls are part of an effort to archive pages as they are created and archive the pages that they refer to. That way, as the pages that are referenced are changed or taken from the web, a link to the version that was live when the page was written will be preserved.
Then the Internet Archive hopes that references to these archived pages will be put in place of a link that would be otherwise be broken, or a companion link to allow people to see what was originally intended by a page's authors.
The goal is to
fix all broken links on the web

Crawls of supported "No More 404" sites.
Collection:
Wikipedia Near Real Time (from IRC)
This is a collection of web page captures from links added to, or changed on, Wikipedia pages. The idea is to bring a reliability to Wikipedia outlinks so that if the pages referenced by Wikipedia articles are changed, or go away, a reader can permanently find what was originally referred to.
This is part of the Internet Archive's attempt to
rid the web of broken links
TIMESTAMPS
The Wayback Machine - https://web.archive.org/web/20161011011103/https://stackoverflow.com/questions/12865093/spring-3-x-json-status-406-characteristics-not-acceptable-according-to-the-requ
current community
chat
Stack Overflow
Meta Stack Overflow
your communities
or
to customize your list.
more stack exchange communities
company blog
Stack Exchange
Inbox
Reputation and Badges
tour
help
Tour
Start here for a quick overview of the site
Detailed answers to any questions you might have
Meta
Discuss the workings and policies of this site
Learn more about Stack Overflow the company
Business
Learn more about hiring developers or posting ads with us
Stack Overflow
Questions
Jobs
Documentation
Tags
Users
Badges
Ask Question
Dismiss
Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Spring 3.x JSON status 406 “characteristics not acceptable according to the request ”accept“ headers ()”
up vote
37
down vote
favorite
14
Upon trying to get my response in
JSON
using
Spring 3.x
, I get the
406 error
"The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the
request
"accept" headers ()."
Here is my environment
* Spring 3.2.0.RELEASE
* included jackson-mapper-asl-1.7.9.jar, jackson-core-asl-1.7.9.jar
* Tomcat 6.x
* mvc:annotation-driven in Spring configuration XML file
My Controller:
@RequestMapping("/contest")
public class ContestController {

@RequestMapping(value="{name}", headers="Accept=*/*", method = RequestMethod.GET)
public @ResponseBody Contest getContestInJSON(@PathVariable String name) {
Contest contest = new Contest();
contest.setName(name);
contest.setStaffName(new String("contestitem1"));

return contest;

My Spring Configuration file
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="




















After this I just access the Controller using below:
and the response I get is Status 406: "The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ()."
I also tried an alternate mechanism by access this using
Javascript
AJAX
to make sure my request header has
application/JSON
but this led to the same Status 406 result
$.getJSON('contest/abcd', function(data) {
console.log(data) }
Here is my REQUEST HEADER captured from browser:
Request URL:http://localhost:8080/SpringWebProject/json/contest/abcd
Request Method:GET
Status Code:406 Not Acceptable

Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:JSESSIONID=59689C95B0B9C21494EB0AB9D9F7BCCD
Host:localhost:8080
Referer:http://localhost:8080/SpringWebProject/json/welcome
User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
X-Requested-With:XMLHttpRequest
Response Headersview source
Content-Length:1070
Content-Type:text/html;charset=utf-8
Date:Fri, 12 Oct 2012 18:23:40 GMT
Server:Apache-Coyote/1.1
Appreciate any help in this regard.
spring
spring-mvc
share
improve this question
edited
Jul 28 '15 at 7:37
Prabhat Singh
170
15
asked
Oct 12 '12 at 18:33
user1740567
188
add a comment
12 Answers
12
active
oldest
votes
up vote
18
down vote
accepted
There is nothing wrong in your configuration, let me suggest a few small changes though:
a) Your namespaces appear wrong - they are referring to the 3.0 schemas, just change them to either 3.1 one's or don't refer to the version explicitly, this way for eg.
xsi:schemaLocation="
OR
xsi:schemaLocation="
b) You don't require the ContentNegotiatingViewResolver, you can remove everything but the
component-scan
and

from your configuration
c) The request will not directly work from the browser as it explicitly requires an Accept header of "application/json" -
$.getJson
call should work though as it sends the correct headers
d) Remove the
headers=Acc..
from the @RequestMapping, and produces also, both are filtering criteria to match up the correct mapped method call.
With these, there is no reason why the json should not get served out, can you please try with these and see how it goes.
share
improve this answer
edited
Sep 16 '14 at 12:02
Ram72119
55
14
answered
Oct 13 '12 at 12:37
Biju Kunjummen
31.1k
56
83
I tried all that you had suggested and also removed version references. No difference though :( here is the mapping information at start up and my JSON request is same as before
INFO: Mapped "{[/contest/{name}],methods=[GET],params=[],headers=[],consu‌​mes=[],produces= [],custom=[]}" onto public com.contestframework.model.Contest com.contestframework.controllers.ContestController.getContes‌​tInJSON(java.lang.St‌​ring)
If you find time, I could send you my exported eclipse project also. Because at this point I am running out of ideas.
user1740567
Oct 16 '12 at 0:58
Yes, if you can create a project and place it on github, I can try to fix it and send you a pull request.
Biju Kunjummen
Oct 16 '12 at 12:13
Thanks - I have provisioned github to your gmail address
user1740567
Oct 17 '12 at 1:07
12
The issue with your project was actually very small - you have protected getters in your Contest class, just change it to public methods and it should just work cleanly.
Biju Kunjummen
Oct 17 '12 at 4:28
I have sent you a github pull request also with the fix.
Biju Kunjummen
Oct 17 '12 at 4:32
show
more comments
up vote
47
down vote
I have also just experienced this same issue. It would appear it is an issue with the latest 3.2.0.RELEASE, as I previously had 3.1.2.RELEASE and it all worked. After changing to 3.2.0.RELEASE it breaks. Have tested with 3.1.3.RELEASE and that works fine. So for now I would suggest rolling back to 3.1.3.RELEASE
EDIT: Thanks to another post on this site that linked to the following location:
I've now got it working by disabling the getting of media type based on the extension of the requested path. This can be done by the following:





And specify version 3.2 for all the xsd schema locations.
And this is using the following jackson jars:

com.fasterxml.jackson.core
jackson-core
2.1.2


com.fasterxml.jackson.core
jackson-databind
2.1.2

share
improve this answer
edited
Jan 14 '13 at 23:15
answered
Dec 18 '12 at 18:35
annihilate
578
12
This is exactly the case with my application. Thanks a ton! I feel like I need to give up 10 times. I have been fruitelessly searching for this issue. This worked like magic.
Kevin Rave
Apr 4 '13 at 4:08
Only jackson-databind was need in my app.
user672009
Oct 17 '14 at 22:10
add a comment
up vote
11
down vote
I had the same problem and I solved it by adding following dependency

org.codehaus.jackson
jackson-mapper-asl
${jackson.version}

Previously I'm doing it with following dependency

com.fasterxml.jackson.core
jackson-core
${com.jackson.core-version}


com.fasterxml.jackson.core
jackson-annotations
${com.jackson.core-version}


com.fasterxml.jackson.core
jackson-databind
${com.jackson.core-version}

In short I have replace com.fasterxml.jackson.core by
org.codehaus.jackson
share
improve this answer
edited
Feb 12 at 10:19
Community
answered
Dec 22 '13 at 6:46
Anupam Pawar
148
Adding dependency for jackson-mapper-asl worked for me.
Harshit
Mar 16 '15 at 0:43
add a comment
up vote
down vote
I had this problem in Spring MVC 4. Adding jackson-annotations, jackson-core and jackson-databind didn't solve the problem. Try this libs:

com.fasterxml.jackson.core
jackson-core
2.1.2


com.fasterxml.jackson.core
jackson-databind
2.1.2


org.codehaus.jackson
jackson-mapper-asl
1.9.13

share
improve this answer
edited
Feb 12 at 10:19
Pardeep Dhingra
2,386
15
39
answered
Aug 29 '14 at 20:10
Weslei Prudencio
163
You nailed it for me, Weslei! I was having this MVC 4. No other solution worked. Thanks a million for saving my day!
asgs
Jun 9 '15 at 18:17
add a comment
up vote
down vote
I think you need to add a produces="application/json" to your @RequestMapping (haven't looked at spring mvc in a while so i'm not 100% positive) ...
16.3.2.6 Producible Media Types
You can narrow the primary mapping by specifying a list of producible media types. The request will be matched only if the Accept request header matches one of these values. Furthermore, use of the produces condition ensures the actual content type used to generate the response respects the media types specified in the produces condition. For example:
@Controller
@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, produces="application/json")
@ResponseBody
public Pet getPet(@PathVariable String petId, Model model) {
// implementation omitted
share
improve this answer
answered
Oct 12 '12 at 18:50
les2
5,426
10
40
70
I just tried that after reading your comment. It gives back the same result status 406. Confirmed the same when server starts the mapping is done correctly with produces option --
INFO: Mapped "{[/contest/{name}],methods=[GET],params=[],headers=[],consu‌​mes=[],produces=[app‌​lication/json || */*],custom=[]}" onto public com.contestframework.model.Contest com.contestframework.controllers.ContestController.getContes‌​tInJSON(java.lang.St‌​ring)
user1740567
Oct 12 '12 at 20:37
@les2, that worked!! I have struggling with the problem, tried adding HttpServletResponse and set content type to "application/json", it wouldn't resolve. 'produces' attribute worked for me.
aces.
Feb 19 '13 at 20:59
add a comment
up vote
down vote
I had the same problem and the comment added by Biju Kunjummen in this answer worked for me perfectly
That is have public getters in my Java class
share
improve this answer
answered
Aug 14 '13 at 9:50
community wiki
OscarRyz
add a comment
up vote
down vote
I had a similar problem, it got resolved when I added
jackson-databind
library.
These are my dependencies:

org.codehaus.jackson
jackson-mapper-asl
1.9.12


com.fasterxml.jackson.core
jackson-databind
2.4.3

share
improve this answer
answered
Dec 12 '14 at 16:19
Smyrnian
126
Thanks for the ASL version numbers, that helped a lot!
abelito
Mar 6 '15 at 17:46
I am glad it helped! In my recent projects I started to use spring boot, no worries for versions or dependencies! ;)
Smyrnian
Mar 9 '15 at 13:11
thanks man i was searching for 2 hours. thought something wrong with my code
Shane Ekanayake
Nov 8 '15 at 19:28
You're welcome. Still, Spring Boot +1 if possible :)
Smyrnian
Nov 10 '15 at 17:51
add a comment
up vote
down vote
Thank you for sharing you experience.I experienced the same problem and it works for me using configuration as show below:
Spring MVC Version : 3.2.5.RELEASE
Apache-tomcat-6.0.24
JDK1.6
jackson-core-asl-1.9.10.jar
jackson-mapper-asl-1.9.10.jar
Spring MVC Config File:





Model class : Country.java
private Integer countryId;
private String name;
//public setters and getters
Controller Method:
@RequestMapping(value = "/get_country_json",method = RequestMethod.GET)
@ResponseBody
public Country getCountry()
Deployment Descriptor(web.xml)

dispatcher
org.springframework.web.servlet.DispatcherServlet
1


dispatcher
*.htm

URL Requested to call controller method: /SpringCURDApp/get_country_json.htm
I hope this can help someone.
share
improve this answer
answered
Apr 23 '14 at 9:13
community wiki
Vikram Thakur
add a comment
up vote
down vote
Don't make the same mistake I did, spend all day playing around with Spring configuration, when actually your object returned in a web service is not marshaling to XML correctly. It seems Spring catches a JAXB marshaling error and doesn't report it. Use this sandbox code to validate JAXB marshaling:
MyClass myclass = new MyClass();
//populate myclass here

JAXBContext context = JAXBContext.newInstance(MyClass.class);

Marshaller m = context.createMarshaller();
StringWriter w = new StringWriter();

m.marshal(myclass, w);
System.out.println(w);
This produced and displayed an exception. Fixed the cause, and my web service is available in both XML and JSON.
share
improve this answer
answered
Sep 5 '14 at 17:59
Steven Neiner
96
This answer must be on the top because everyone must start checking from this stage only !!! Thanks :)
ADi
Nov 11 '14 at 18:43
add a comment
up vote
down vote
Shortly:
For Spring MVC 4.1.6 there is enough:

com.fasterxml.jackson.core
jackson-databind
2.5.0

jackson-databind
has dependency on
core
and
annotations
artifacts.
In details:
What is
HTTP 406
error?
406 Not Acceptable
The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.
It means that Server cannot generate content which
MEDIA TYPE
stated in
Accept
Header.
But how does server know which
MEDIA TYPE
it can generate and which not?
Spring Web has concept of
HttpMessageConverter
. Some of these converters are already registered in Spring and
AbstractMessageConverterMethodArgumentResolver
holds them in property
messageConverters
During request processing
AbstractMessageConverterMethodProcessor
analyzes what spring can convert and saves all supported
MEDIA TYPES
in
producibleMediaTypes
variable.
If requested
MEDIA TYPE
is not producible then says Error 406 == I cannot generated requested media type. Sorry.
To cut the long story short - register required converters. In your case it's jackson library which produces
application/json
share
improve this answer
edited
Feb 12 at 10:20
Pardeep Dhingra
2,386
15
39
answered
Jun 10 '15 at 21:36
shevchyk
19.8k
37
47
add a comment
up vote
down vote
Please, see
As you can see
"For file extensions in the request URI, the MVC Java config and the
MVC namespace, automatically register extensions such as .json, .xml,
.rss, and .atom if the corresponding dependencies such as Jackson,
JAXB2, or Rome are present on the classpath."
You should add ".json" at the end of URI (like
It works for me.
share
improve this answer
answered
Jun 7 '15 at 7:23
Georgii Goriachev
41
add a comment
up vote
-1
down vote
If you are using Spring 4 then you must only update your libraries:

com.fasterxml.jackson.core
jackson-core
2.3.0


com.fasterxml.jackson.core
jackson-databind
2.3.0

share
improve this answer
answered
May 30 '15 at 6:06
Daniel Rojas
29
add a comment
Not the answer you're looking for? Browse other questions tagged
spring
spring-mvc
or
ask your own question
asked
3 years ago
viewed
53848 times
active
8 months ago
Get the
weekly newsletter!
In it, you'll get:
The week's top questions and answers
Important community announcements
Questions that need answers
see an
example newsletter
By subscribing, you agree to the
and
Linked
Failed to load resource: the server responded with a status of 406 (Not Acceptable)
Is Json Support in Spring MVC 3.2 broken?
Saving object with 1-to-n cardinality
Related
23
spring mvc not returning json content - error 406
12
Spring-MVC 406 Not Acceptable instead of JSON Response
34
Spring MVC + JSON = 406 Not Acceptable
Spring 406 not acceptable request from ajax
HTTP Status 406. Spring MVC 4.0, jQuery, JSON
10
406 Spring MVC Json, not acceptable according to the request “accept” headers
Spring 4 RestController JSON: characteristics not acceptable according to the request “accept” headers
Error 406: JSON response could not be returned in spring 3.x
HTTP Status 406 :Spring JSON request
responses with characteristics not acceptable according to the request “accept” headers
Hot Network Questions
Mapping many-to-many relationship
Can Communism become a stable economic strategy? How?
Where are the oil platforms in Google Earth?
Can a new platform / cryptocurrency be built on top of Monero?
Converting SCART to VGA/Jack
Section of a book that explains things
Create "gold" from lead (or other substances)
Simulate keystrokes
Usage of the word "steward"
What would be a good approach to make sure my advisor goes through all the report?
How do I remove the remaining part of a word in the shell?
How to challenge optimized player with Sharpshooter feat
Will credit card payment from abroad be suspicious as taxable income?
What would it take to make thorium a prominent energy source?
The need for the Gram–Schmidt process
A power source that would last a REALLY long time
How could I do all of this in a more effective way?
Can I stack an Animated Shield with the Shield spell?
The Guard Of Fantasy
When must I use #!/bin/bash and when #!/bin/sh?
Can Homeowners insurance be cancelled for non-removal of tree debris?
Why divorcing your first wife should be done only in extreme cases?
Stopping time, by speeding it up inside a bubble
Should I serve jury duty when I have no respect for the judge?
more hot questions
question feed
default
tour
help
blog
chat
data
legal
work here
advertising info
mobile
feedback
Technology
Life / Arts
Culture / Recreation
Science
Other
Stack Overflow
Server Fault
Super User
Web Applications
Ask Ubuntu
Webmasters
Game Development
TeX - LaTeX
Programmers
Unix & Linux
Ask Different (Apple)
WordPress Development
Geographic Information Systems
Electrical Engineering
Android Enthusiasts
Information Security
Database Administrators
Drupal Answers
SharePoint
User Experience
Mathematica
Salesforce
ExpressionEngine® Answers
Cryptography
Code Review
Magento
Signal Processing
Raspberry Pi
Programming Puzzles & Code Golf
more (7)
Photography
Science Fiction & Fantasy
Graphic Design
Movies & TV
Music: Practice & Theory
Seasoned Advice (cooking)
Home Improvement
Personal Finance & Money
Academia
more (8)
English Language & Usage
Skeptics
Mi Yodeya (Judaism)
Travel
Christianity
English Language Learners
Japanese Language
Arqade (gaming)
Bicycles
Role-playing Games
Anime & Manga
more (18)
Mathematics
Cross Validated (stats)
Theoretical Computer Science
Physics
MathOverflow
Chemistry
Biology
Computer Science
Philosophy
more (3)
Stack Apps
Meta Stack Exchange
Area 51
Stack Overflow Careers
site design / logo © 2016 Stack Exchange Inc; user contributions licensed under
cc by-sa 3.0
with
attribution required
rev 2016.10.10.4051