Trying to come up with a clever title for a blog post is not easy.
This problem caused me headaches for 2 days and as much as I have resolved it I have no idea why and how it happened.
I have done REST application with Spring many times in the past and it easy. At one point in the process for this one I was creating REST application with STS just to confirm that it was a no brainer, which helped and puzzled me.
The simplest class that worked for me was something like this:
@Controller @RequestMapping(value="/rest") public class Rest { @RequestMapping(value="/{something}", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE) @ResponseBody public String[] firstTry(@PathVariable String something){ return new String[]{something, "testValue"}; } }
I could quickly package it with Maven and run it on Wildfly and it would work as expected.
When I tried to do the same in IntelliJ I was getting a non working application that returned a 406, Not Acceptable, return code to all REST calls.
I compared the web.xml, the application context xml files, the pom files, everything I could thing of and the STS app would work with nothing special but the IntelliJ app would not.
Most articles I was finding were talking about bugs in some version of Spring and to make sure you had the element in your application context xml. I tried many version and adding the annotation driven did not fix the issue.
I finally found this article that explained that you needed to make sure you specified the jackson-databind library in your pom.xml otherwise you would get 406 answers. Once I added the jackson libraries to my project from IntelliJ I was able to get things to work as expected.
No Jackson libraries are specified in my STS generated project and they work so I am still puzzled as to why this was needed in the IntelliJ project.