POSTS

Java - SpringMVC NetworkError 406 Not Acceptable while using JSON

Problem:

“NetworkError 406 Not Acceptable” when calling a servlet using jQuery and expecting a JSON result.
<![CDATA[ function getRecipeNutritionalInformation(recipe) { $.getJSON(“http://xxx/getRecipeNutritionalInformation?recipe=" + recipe, function(data){ res=jQuery.stringify(data); $.each(data, function(index) { alert(index); }); }) .success(function() { alert(“success”);}) .error(function(XMLHttpRequest, textStatus, errorThrown) { alert(“textStatus “+textStatus); alert(“errorThrown “+errorThrown);}) .complete(function() { alert(“complete”);}) ; } @RequestMapping(method=RequestMethod.GET, value=“/getRecipeNutritionalInformation”) public @ResponseBody NutritionalFacts getRecipeNutritionalInformation(@RequestParam(“recipe”) String input) { (…) } ]]>

Solution:

The JSON converting Maven dependencies (or plain libraries) might be missing on the project classpath:
<![CDATA[ javax.xml.bind jaxb-api 2.2.6 org.codehaus.jackson jackson-mapper-asl 1.4.2 org.codehaus.jackson jackson-core-asl 1.4.2]]>

SyntaxHighlighter.highlight();