Ok, so I've been looking at this for a little while now and am no further on. I've got a Spring MVC servlet that I need to accept JSON from a JavaScript front end web app. To parse the JSON I need to use Jackson. I need to take the values within the JSON and store them into a List in the order they appear in the JSON. I've tried using the JsonFactory with the JsonParser and JsonNode objects but can quite get it to work. I've also tried to just open a BufferedReader and iterate through the request body line by line but again can't quite get this either. I've looked at a couple of related questions on here, but none so far have worked for me.
Could anyone in the know point me in the right direction here please, a web page with an example would be great!
The whole point of using a mapping technology like Jackson is that you can use Objects (you don't have to parse the JSON yourself).
Define a Java class that resembles the JSON you will be expecting.
e.g. this JSON:
could be mapped to this class:
Now if you have a Controller method like this:
and you pass in the JSON from above, Jackson will automatically create a Fizzle object for you, and it will serialize a JSON view of the returned Object out to the response with mime type
application/json
.For a full working example see this previous answer of mine.
I'm using json lib from http://json-lib.sourceforge.net/
json-lib-2.1-jdk15.jar
More samples here http://json-lib.sourceforge.net/usage.html