{title:'Complex Data Types', created:'9.0.0'}

The Juneau parsers have the ability to parse into complex data types that consist of multidimensional arrays and nested maps and collections using the methods below:

Arrays are simple enough and can be constructed using the first method:

| String json = "[1,2,3]"; | int[] array = Json.to(json, int[].class);

For data types consisting of nested collections an maps such as Map<String,List<MyBean>>, you need to use the second parse method that allows you to define the parameter types of the collections classes. For example:

| String json = "{foo:[{bar:'baz'}]}"; | TreeMap<String,List<MyBean>> map = Json.to( | json, // Input being parsed. | TreeMap.class, // Top-level data type. | String.class, // Key type of map. | LinkedList.class, // Value type of map. | MyBean.class // Value type of list. | );

Collection classes are assumed to be followed by zero or one objects indicating the element type.
Map classes are assumed to be followed by zero or two meta objects indicating the key and value types.
The arguments can be arbitrarily long to indicate arbitrarily complex data structures.

Similar methods for converting to complex types can be found on the {@link oajr.httppart.RequestContent} and {@link oajr.httppart.RequestHttpPart} classes, and the {@link oaj.BeanSession#convertToType(Object,Type,Type...)} method.