in johnzon-mapper/src/main/java/org/apache/johnzon/mapper/MappingParserImpl.java [826:1033]
private Object buildArrayWithComponentType(final JsonArray jsonArray, final Class<?> componentType, final Adapter itemConverter,
final JsonPointerTracker jsonPointer, final Type rootType) {
if (boolean.class == componentType) {
boolean[] array = new boolean[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
final Object object = toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
if (object == null) {
throw new IllegalStateException("json array mapped to boolean[] has null value at index " + i);
}
array[i] = (boolean) object;
i++;
}
return array;
}
if (byte.class == componentType) {
byte[] array = new byte[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
final Object object = toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
if (object == null) {
throw new IllegalStateException("json array mapped to byte[] has null value at index " + i);
}
array[i] = (byte) object;
i++;
}
return array;
}
if (char.class == componentType) {
char[] array = new char[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
final Object object = toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
if (object == null) {
throw new IllegalStateException("json array mapped to char[] has null value at index " + i);
}
array[i] = (char) object;
i++;
}
return array;
}
if (short.class == componentType) {
short[] array = new short[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
final Object object = toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
if (object == null) {
throw new IllegalStateException("json array mapped to short[] has null value at index " + i);
}
array[i] = (short) object;
i++;
}
return array;
}
if (int.class == componentType) {
int[] array = new int[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
final Object object = toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
if (object == null) {
throw new IllegalStateException("json array mapped to int[] has null value at index " + i);
}
array[i] = (int) object;
i++;
}
return array;
}
if (long.class == componentType) {
long[] array = new long[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
final Object object = toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
if (object == null) {
throw new IllegalStateException("json array mapped to long[] has null value at index " + i);
}
array[i] = (long) object;
i++;
}
return array;
}
if (float.class == componentType) {
float[] array = new float[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
final Object object = toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
if (object == null) {
throw new IllegalStateException("json array mapped to float[] has null value at index " + i);
}
array[i] = (float) object;
i++;
}
return array;
}
if (double.class == componentType) {
double[] array = new double[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
final Object object = toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
if (object == null) {
throw new IllegalStateException("json array mapped to double[] has null value at index " + i);
}
array[i] = (double) object;
i++;
}
return array;
}
// wrapper types
if (Boolean.class == componentType) {
Boolean[] array = new Boolean[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
array[i] = (Boolean) toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
i++;
}
return array;
}
if (Byte.class == componentType) {
Byte[] array = new Byte[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
array[i] = (Byte) toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
i++;
}
return array;
}
if (Character.class == componentType) {
Character[] array = new Character[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
array[i] = (Character) toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
i++;
}
return array;
}
if (Short.class == componentType) {
Short[] array = new Short[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
array[i] = (Short) toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
i++;
}
return array;
}
if (Integer.class == componentType) {
Integer[] array = new Integer[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
array[i] = (Integer) toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
i++;
}
return array;
}
if (Long.class == componentType) {
Long[] array = new Long[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
array[i] = (Long) toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
i++;
}
return array;
}
if (Float.class == componentType) {
Float[] array = new Float[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
array[i] = (Float) toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
i++;
}
return array;
}
if (Double.class == componentType) {
Double[] array = new Double[jsonArray.size()];
int i = 0;
for (final JsonValue value : jsonArray) {
array[i] = (Double) toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType);
i++;
}
return array;
}
// for all the rest we have to rely on reflection :(
final Object array = Array.newInstance(componentType, jsonArray.size());
int i = 0;
for (final JsonValue value : jsonArray) {
Array.set(array, i, toObject(null, value, componentType, itemConverter,
isDedup() ? new JsonPointerTracker(jsonPointer, i) : null, rootType));
i++;
}
return array;
}