return (T)newArray;\r
}\r
if (ClassReflection.isAssignableFrom(List.class, type)) {\r
- List newArray = type == null ? new ArrayList() : (List)newInstance(type);\r
+ List newArray = (type == null || type.isInterface()) ? new ArrayList() : (List)newInstance(type);\r
for (JsonValue child = jsonData.child(); child != null; child = child.next())\r
newArray.add(readValue(elementType, null, child));\r
return (T)newArray;\r
if (type.isArray()) {\r
Class componentType = type.getComponentType();\r
if (elementType == null) elementType = componentType;\r
- Object newArray = ArrayReflection.newInstance(componentType, jsonData.size());\r
+ Object newArray = ArrayReflection.newInstance(componentType, jsonData.size);\r
int i = 0;\r
for (JsonValue child = jsonData.child(); child != null; child = child.next())\r
ArrayReflection.set(newArray, i++, readValue(elementType, null, child));\r
\r
public FieldMetadata (Field field) {\r
this.field = field;\r
- this.elementType = field.getElementType();\r
+ int index = (ClassReflection.isAssignableFrom(ObjectMap.class, field.getType()) || ClassReflection.isAssignableFrom(\r
+ HashMap.class, field.getType())) ? 1 : 0;\r
+ this.elementType = field.getElementType(index);\r
}\r
}\r
\r
package com.badlogic.gdx.utils.reflect;
+import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
return field.isSynthetic();
}
- /** If the type of the field is parameterized, returns the Class object representing the parameter type, null otherwise. */
- public Class getElementType () {
+ /** If the type of the field is parameterized, returns the Class object representing the parameter type at the specified index,
+ * null otherwise. */
+ public Class getElementType (int index) {
Type genericType = field.getGenericType();
if (genericType instanceof ParameterizedType) {
Type[] actualTypes = ((ParameterizedType)genericType).getActualTypeArguments();
- if (actualTypes.length == 1) {
- Type actualType = actualTypes[0];
+ if (actualTypes.length - 1 >= index) {
+ Type actualType = actualTypes[index];
if (actualType instanceof Class)
return (Class)actualType;
- else if (actualType instanceof ParameterizedType) return (Class)((ParameterizedType)actualType).getRawType();
+ else if (actualType instanceof ParameterizedType)
+ return (Class)((ParameterizedType)actualType).getRawType();
+ else if (actualType instanceof GenericArrayType) {
+ Type componentType = ((GenericArrayType)actualType).getGenericComponentType();
+ if (componentType instanceof Class) return ArrayReflection.newInstance((Class)componentType, 0).getClass();
+ }
}
}
return null;