return;
}
Class<?> clazz = data.getClass();
ClassInfo classInfo = ClassInfo.of(clazz);
List<Type> context = Arrays.<Type>asList(clazz);
GenericData genericData = GenericData.class.isAssignableFrom(clazz) ? (GenericData) data : null;
@SuppressWarnings("unchecked")
Map<Object, Object> map = Map.class.isAssignableFrom(clazz) ? (Map<Object, Object>) data : null;
ArrayValueMap arrayValueMap = new ArrayValueMap(data);
int cur = 0;
int length = content.length();
int nextEquals = content.indexOf('=');
while (cur < length) {
// parse next parameter
int amp = content.indexOf('&', cur);
if (amp == -1) {
amp = length;
}
String name;
String stringValue;
if (nextEquals != -1 && nextEquals < amp) {
name = content.substring(cur, nextEquals);
stringValue = CharEscapers.decodeUri(content.substring(nextEquals + 1, amp));
nextEquals = content.indexOf('=', amp + 1);
} else {
name = content.substring(cur, amp);
stringValue = "";
}
name = CharEscapers.decodeUri(name);
// get the field from the type information
FieldInfo fieldInfo = classInfo.getFieldInfo(name);
if (fieldInfo != null) {
Type type = Data.resolveWildcardTypeOrTypeVariable(context, fieldInfo.getGenericType());
// type is now class, parameterized type, or generic array type
if (Types.isArray(type)) {
// array that can handle repeating values
Class<?> rawArrayComponentType = Types.getRawArrayComponentType(
context, Types.getArrayComponentType(type));
arrayValueMap.put(fieldInfo.getField(), rawArrayComponentType,
parseValue(rawArrayComponentType, context, stringValue));
} else if (Types.isAssignableToOrFrom(
Types.getRawArrayComponentType(context, type), Iterable.class)) {
// iterable that can handle repeating values
@SuppressWarnings("unchecked")
Collection<Object> collection = (Collection<Object>) fieldInfo.getValue(data);
if (collection == null) {
collection = Data.newCollectionInstance(type);
fieldInfo.setValue(data, collection);
}
Type subFieldType = type == Object.class ? null : Types.getIterableParameter(type);
collection.add(parseValue(subFieldType, context, stringValue));
} else {
// parse into a field that assumes it is a single value
fieldInfo.setValue(data, parseValue(type, context, stringValue));
}
} else if (map != null) {
// parse into a map: store as an ArrayList of values
@SuppressWarnings("unchecked")
ArrayList<String> listValue = (ArrayList<String>) map.get(name);
if (listValue == null) {
listValue = new ArrayList<String>();
if (genericData != null) {
genericData.set(name, listValue);
} else {
map.put(name, listValue);
}
}
listValue.add(stringValue);