If the reflective type isn't as expected, fail with a JsonSyntaxException

This commit is contained in:
Jesse Wilson 2011-09-09 08:10:57 +00:00
parent 1bb48694f4
commit ee9ffa808a

View File

@ -16,6 +16,7 @@
package com.google.gson.internal.bind; package com.google.gson.internal.bind;
import com.google.gson.JsonSyntaxException;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.AccessibleObject; import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -72,8 +73,8 @@ public final class ReflectiveTypeAdapter<T> extends TypeAdapter<T> {
// TODO: null out the other fields? // TODO: null out the other fields?
reader.beginObject();
try { try {
reader.beginObject();
while (reader.hasNext()) { while (reader.hasNext()) {
String name = reader.nextName(); String name = reader.nextName();
BoundField field = map.get(name); BoundField field = map.get(name);
@ -84,6 +85,8 @@ public final class ReflectiveTypeAdapter<T> extends TypeAdapter<T> {
field.read(reader, instance); field.read(reader, instance);
} }
} }
} catch (IllegalStateException e) {
throw new JsonSyntaxException(e);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new AssertionError(); throw new AssertionError();
} }