Below is an example of an approach that you can use with Jackson. It uses the same JSON structure as in the latest issue updates, as well as the corresponding Java data structure. This makes it very easy to deserialize with just one line of code.
I decided to just deserialize the JSON array into a Java list. This is very easy to change to use a Java array instead.
(Note that there are problems with this JSON structure that I suggest changing if it is in your control to change it.)
input.json:
{ "objects": { "array1": [ { "element1": "value1", "element2": "value2", "element3": "value3" } ], "array2": [ { "element1": "value1", "element2": "value2", "element3": "value3" } ], "array3": [ { "element1": "value1", "element2": "value2", "element3": "value3" } ] } }
Java Code:
import java.io.File; import java.util.List; import java.util.Map; import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility; import org.codehaus.jackson.map.ObjectMapper; public class Foo { public static void main(String[] args) throws Exception { ObjectMapper mapper = new ObjectMapper();
source share