import java.beans.PropertyDescriptor;
import java.io.Serializable;
import java.lang.reflect.Array;
+import java.lang.reflect.GenericArrayType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
private static Class<?> getClassForType(Type type) {
if (type instanceof ParameterizedType) {
return (Class<?>) (((ParameterizedType) type).getRawType());
- } else {
+ } else if (type instanceof Class<?>) {
return (Class<?>) type;
+ } else {
+ return null;
}
}
&& ((Class<?>) targetType).isArray()) {
// Legacy Object[] and String[] handled elsewhere, this takes care
// of generic arrays
- return decodeArray((Class<?>) targetType, (JSONArray) value,
+ Class<?> componentType = ((Class<?>) targetType).getComponentType();
+ return decodeArray(componentType, (JSONArray) value,
+ connectorTracker);
+ } else if (targetType instanceof GenericArrayType) {
+ Type componentType = ((GenericArrayType) targetType)
+ .getGenericComponentType();
+ return decodeArray(componentType, (JSONArray) value,
connectorTracker);
} else if (targetType == JSONObject.class
|| targetType == JSONArray.class) {
}
}
- private static Object decodeArray(Class<?> targetType, JSONArray value,
+ private static Object decodeArray(Type componentType, JSONArray value,
ConnectorTracker connectorTracker) throws JSONException {
- Class<?> componentType = targetType.getComponentType();
- Object array = Array.newInstance(componentType, value.length());
+ Class<?> componentClass = getClassForType(componentType);
+ Object array = Array.newInstance(componentClass, value.length());
for (int i = 0; i < value.length(); i++) {
Object decodedValue = decodeInternalOrCustomType(componentType,
value.get(i), connectorTracker);
return jsonArray;
} else if (valueType instanceof Class<?>
&& ((Class<?>) valueType).isArray()) {
- JSONArray jsonArray = encodeArrayContents(value, connectorTracker);
+ JSONArray jsonArray = encodeArrayContents(
+ ((Class<?>) valueType).getComponentType(), value,
+ connectorTracker);
+ return jsonArray;
+ } else if (valueType instanceof GenericArrayType) {
+ Type componentType = ((GenericArrayType) valueType)
+ .getGenericComponentType();
+ JSONArray jsonArray = encodeArrayContents(componentType, value,
+ connectorTracker);
return jsonArray;
} else if (value instanceof Map) {
Object jsonMap = encodeMap(valueType, (Map<?, ?>) value,
return e.name();
}
- private static JSONArray encodeArrayContents(Object array,
- ConnectorTracker connectorTracker) throws JSONException {
+ private static JSONArray encodeArrayContents(Type componentType,
+ Object array, ConnectorTracker connectorTracker)
+ throws JSONException {
JSONArray jsonArray = new JSONArray();
- Class<?> componentType = array.getClass().getComponentType();
for (int i = 0; i < Array.getLength(array); i++) {
jsonArray.put(encode(Array.get(array, i), null, componentType,
connectorTracker));
rpc.sendList(Arrays.asList(5, 8, -234), Arrays.<Connector> asList(this,
testExtension), Arrays.asList(new SimpleTestBean(234),
new SimpleTestBean(-568)));
- // Disabled because of #8861
- // rpc.sendArrayList(
- // Arrays.asList(new int[] { 1, 2 }, new int[] { 3, 4 }),
- // Arrays.asList(new Integer[] { 5, 6 }, new Integer[] { 7, 8 }),
- // Collections
- // .singletonList(new SimpleTestBean[] { new SimpleTestBean(
- // 7) }));
+ rpc.sendArrayList(
+ Arrays.asList(new int[] { 1, 2 }, new int[] { 3, 4 }),
+ Arrays.asList(new Integer[] { 5, 6 }, new Integer[] { 7, 8 }),
+ Collections
+ .singletonList(new SimpleTestBean[] { new SimpleTestBean(
+ 7) }));
// Disabled because of #8861
// rpc.sendListArray(
// new List[] { Arrays.asList(1, 2), Arrays.asList(3, 4) },
public void sendArrayList(List<int[]> primitiveArrayList,
List<Integer[]> objectArrayList,
List<SimpleTestBean[]> beanArrayList) {
- log.log("sendArrayList: " + primitiveArrayList + ", "
- + objectArrayList + ", " + beanArrayList);
+ log.log("sendArrayList: "
+ + Arrays.deepToString(primitiveArrayList.toArray())
+ + ", " + Arrays.deepToString(objectArrayList.toArray())
+ + ", " + Arrays.deepToString(beanArrayList.toArray()));
}
public void sendListArray(List<Integer>[] objectListArray,