@Test public void createsArrayOfStrings() throws Exception { ArrayValue jsonArray = createJsonArray("to", "be", "or", "not", "to", "be"); Object array = ObjectBuilder.createArray(String[].class, jsonArray); assertArrayEquals(new String[]{"to", "be", "or", "not", "to", "be"}, (Object[])array); }
public static Object createArray(Class<?> aClass, JsonValue jsonArray) throws JsonException { if (jsonArray == null || jsonArray.isNull()) { return null; } Class<?> componentType = aClass.getComponentType(); Object array = Array.newInstance(componentType, jsonArray.size()); Iterator<JsonValue> values = jsonArray.getElements(); int i = 0; if (componentType.isArray()) { if (isKnownType(componentType)) { while (values.hasNext()) { Array.set(array, i++, createObjectKnownTypes(componentType, values.next())); } } else { while (values.hasNext()) { Array.set(array, i++, createArray(componentType, values.next())); } } } else { if (isKnownType(componentType)) { while (values.hasNext()) { Array.set(array, i++, createObjectKnownTypes(componentType, values.next())); } } else { while (values.hasNext()) { Array.set(array, i++, createObject(componentType, values.next())); } } } return array; }
ObjectBuilder { public static Object createArray(Class<?> aClass, JsonValue jsonArray) throws JsonException { if (jsonArray == null || jsonArray.isNull()) { return null; } Class<?> componentType = aClass.getComponentType(); Object array = Array.newInstance(componentType, jsonArray.size()); Iterator<JsonValue> values = jsonArray.getElements(); int i = 0; if (componentType.isArray()) { if (isKnownType(componentType)) { while (values.hasNext()) { Array.set(array, i++, createObjectKnownTypes(componentType, values.next())); } } else { while (values.hasNext()) { Array.set(array, i++, createArray(componentType, values.next())); } } } else { if (isKnownType(componentType)) { while (values.hasNext()) { Array.set(array, i++, createObjectKnownTypes(componentType, values.next())); } } else { while (values.hasNext()) { Array.set(array, i++, createObject(componentType, values.next())); } } } return array; } }
ObjectBuilder { public static Object createArray(Class<?> aClass, JsonValue jsonArray) throws JsonException { if (jsonArray == null || jsonArray.isNull()) { return null; } Class<?> componentType = aClass.getComponentType(); Object array = Array.newInstance(componentType, jsonArray.size()); Iterator<JsonValue> values = jsonArray.getElements(); int i = 0; if (componentType.isArray()) { if (isKnownType(componentType)) { while (values.hasNext()) { Array.set(array, i++, createObjectKnownTypes(componentType, values.next())); } } else { while (values.hasNext()) { Array.set(array, i++, createArray(componentType, values.next())); } } } else { if (isKnownType(componentType)) { while (values.hasNext()) { Array.set(array, i++, createObjectKnownTypes(componentType, values.next())); } } else { while (values.hasNext()) { Array.set(array, i++, createObject(componentType, values.next())); } } } return array; } private  ObjectBuilder(); }
ObjectBuilder { public static Object createArray(Class<?> aClass, JsonValue jsonArray) throws JsonException { if (jsonArray == null || jsonArray.isNull()) { return null; } Class<?> componentType = aClass.getComponentType(); Object array = Array.newInstance(componentType, jsonArray.size()); Iterator<JsonValue> values = jsonArray.getElements(); int i = 0; if (componentType.isArray()) { if (isKnownType(componentType)) { while (values.hasNext()) { Array.set(array, i++, createObjectKnownTypes(componentType, values.next())); } } else { while (values.hasNext()) { Array.set(array, i++, createArray(componentType, values.next())); } } } else { if (isKnownType(componentType)) { while (values.hasNext()) { Array.set(array, i++, createObjectKnownTypes(componentType, values.next())); } } else { while (values.hasNext()) { Array.set(array, i++, createObject(componentType, values.next())); } } } return array; } private  ObjectBuilder(); static Object createArray(Class<?> aClass, JsonValue jsonArray); @SuppressWarnings("unchecked") static T createCollection(Class<T> collectionClass, Type genericType, JsonValue jsonArray); @SuppressWarnings("unchecked") static T createObject(Class<T> mapClass, Type genericType, JsonValue jsonObject); @SuppressWarnings({"unchecked"}) static T createObject(Class<T> aClass, JsonValue jsonValue); }
ObjectBuilder { public static Object createArray(Class<?> aClass, JsonValue jsonArray) throws JsonException { if (jsonArray == null || jsonArray.isNull()) { return null; } Class<?> componentType = aClass.getComponentType(); Object array = Array.newInstance(componentType, jsonArray.size()); Iterator<JsonValue> values = jsonArray.getElements(); int i = 0; if (componentType.isArray()) { if (isKnownType(componentType)) { while (values.hasNext()) { Array.set(array, i++, createObjectKnownTypes(componentType, values.next())); } } else { while (values.hasNext()) { Array.set(array, i++, createArray(componentType, values.next())); } } } else { if (isKnownType(componentType)) { while (values.hasNext()) { Array.set(array, i++, createObjectKnownTypes(componentType, values.next())); } } else { while (values.hasNext()) { Array.set(array, i++, createObject(componentType, values.next())); } } } return array; } private  ObjectBuilder(); static Object createArray(Class<?> aClass, JsonValue jsonArray); @SuppressWarnings("unchecked") static T createCollection(Class<T> collectionClass, Type genericType, JsonValue jsonArray); @SuppressWarnings("unchecked") static T createObject(Class<T> mapClass, Type genericType, JsonValue jsonObject); @SuppressWarnings({"unchecked"}) static T createObject(Class<T> aClass, JsonValue jsonValue);  }