if (pos >= 0)
{
int endPos = targetType.lastIndexOf(']');
if (endPos < pos)
{
throw new ExecutionException("Mismatched brackets in type name.");
}
String listType = targetType.substring(0, pos);
String elementType = targetType.substring(pos + 1, endPos);
// Unimplemented feature: if listType is an empty string, then handle it as an array
Class listClass = Class.forName(listType);
if (!Collection.class.isAssignableFrom(listClass))
{
throw new ExecutionException("List class '" + listType + "' must implement Collection.");
}
Collection list;
try
{
list = (Collection) listClass.getConstructor().newInstance();
}
catch (Exception ex)
{
throw new ExecutionException("Cannot instantiate list class '" + listType + "'.");
}
fillList(jsonContainer.getJSONArray(fieldName), list, elementType);
return list;
}