I have a Spring MVC
project with Maven
managing dependencies. I need to read the JSON and display its content to the view.
Given a simple JSON object
{
"items" : [{"model" : "m1"}, {"model" : "m2"}, {"model" : "m3"}]
}
I leverage packages from Jackson Project to read and parse the file, and then set the value in @Controller
JsonNode itemsNode = Node.path("items");
model.addAttribute("items", itemsNode);
On the JSP, I retrieve the values
Item 0: ${items.get(0)}, Item 1: ${items.get(1)}, Item 2: ${items.get(2)}
The problem I encountered is,
everything works as expected when I use
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
but I got error,
HTTP Status 500 - javax.el.MethodNotFoundException: Unable to find unambiguous method: class com.fasterxml.jackson.databind.node.ArrayNode.get(java.lang.Long)
when I replaced both <dependency>
to
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.1</version>
</dependency>
with no source code changes(except import
statements). Spring is 4.1.5.RELEASE