@SuppressWarnings("unchecked")
public <T> T parseValue(int order, Type type) {
if(json.isJsonArray()) {
JsonArray jsonArray = json.getAsJsonArray();
if(jsonArray.size() <= order) {
throw new DirectException("Transaction data list of values cannot doesn't contain parameter with order index: " + order + " cause is too short: " + jsonArray.size());
}
JsonElement jsonElement = jsonArray.get(order);
if(type instanceof ParameterizedType && Collection.class.isAssignableFrom((Class)((ParameterizedType)type).getRawType())) {
Class collectionClass = (Class) ((ParameterizedType) type).getRawType();
Object collectionArg = this.context.deserialize(jsonElement, this.getArrayComponentType(type));
Collection collection = Set.class.isAssignableFrom(collectionClass) ? new HashSet(1) : new ArrayList(1);
collection.add(collectionArg);
return (T) collection;
}
if(this.isArray(type) && jsonElement.isJsonObject()) {
Object arrayArg = this.context.deserialize(jsonElement, this.getArrayComponentType(type));
Object[] array = (Object[]) Array.newInstance(this.getArrayComponentType(type), 1);
array[0] = arrayArg;
return (T) array;
}
return (T) this.context.deserialize(jsonElement, type);
}
throw new DirectException("Transaction data aren't a list of values, cannot access through parameter order index: " + order);
}