if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
MailChimpObject result;
try {
result = constructor.newInstance();
} catch(Exception e) {
throw new RuntimeException("Failed to invoke " + constructor + " with no args", e);
}
in.beginObject();
while (in.hasNext()) {
final String key;
if (in.peek() == JsonToken.NAME) {
key = in.nextName();
} else {
key = in.nextString();
}
final Object value;
Type valueType = result.getReflectiveMappingTypes().get(key);
if (valueType != null) {
value = gson.getAdapter(TypeToken.get(valueType)).read(in);
} else {
if (in.peek() == JsonToken.BEGIN_OBJECT) {
value = gson.getAdapter(MailChimpObject.class).read(in);
} else if(in.peek() == JsonToken.BEGIN_ARRAY) {
value = readList(in);
} else {
value = gson.getAdapter(Object.class).read(in);
}
}
if (result.put(key, value) != null) {
throw new JsonSyntaxException("duplicate key: " + key);
}
}
in.endObject();