使用Rxjava+Retrofit开发的时候,GSON抛出了
com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: empty String
因为没有索引,解决起来很是恼火。
解决办法:
定位到类
ReflectiveTypeAdapterFactory
@Override public T read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
T instance = constructor.construct();
try {
in.beginObject();
while (in.hasNext()) {
String name = in.nextName();
BoundField field = boundFields.get(name);
if (field == null || !field.deserialized) {
in.skipValue();
} else {
field.read(in, instance);
}
}
} catch (IllegalStateException e) {
throw new JsonSyntaxException(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
}
in.endObject();
return instance;
}
开启debug模式,一步步跟踪,哪个步骤抛出异常了,就说明哪个字段不对。