Revert most of r677: Required strings to be quoted even in lenient mode. As far as Inderjeet and I can tell, this is consistent with Gson 1.5.
This commit is contained in:
parent
d87eed510b
commit
1c5f5132d8
@ -17,8 +17,9 @@
|
|||||||
package com.google.gson;
|
package com.google.gson;
|
||||||
|
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonToken;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
import com.google.gson.stream.MalformedJsonException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
@ -455,6 +456,7 @@ public final class Gson {
|
|||||||
public <T> T fromJson(Reader json, Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
|
public <T> T fromJson(Reader json, Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
|
||||||
JsonReader jsonReader = new JsonReader(json);
|
JsonReader jsonReader = new JsonReader(json);
|
||||||
Object object = fromJson(jsonReader, classOfT);
|
Object object = fromJson(jsonReader, classOfT);
|
||||||
|
assertFullConsumption(object, jsonReader);
|
||||||
return Primitives.wrap(classOfT).cast(object);
|
return Primitives.wrap(classOfT).cast(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,7 +481,21 @@ public final class Gson {
|
|||||||
*/
|
*/
|
||||||
public <T> T fromJson(Reader json, Type typeOfT) throws JsonIOException, JsonSyntaxException {
|
public <T> T fromJson(Reader json, Type typeOfT) throws JsonIOException, JsonSyntaxException {
|
||||||
JsonReader jsonReader = new JsonReader(json);
|
JsonReader jsonReader = new JsonReader(json);
|
||||||
return this.<T>fromJson(jsonReader, typeOfT);
|
T object = this.<T>fromJson(jsonReader, typeOfT);
|
||||||
|
assertFullConsumption(object, jsonReader);
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertFullConsumption(Object obj, JsonReader reader) {
|
||||||
|
try {
|
||||||
|
if (obj != null && reader.peek() != JsonToken.END_DOCUMENT) {
|
||||||
|
throw new JsonIOException("JSON document was not fully consumed.");
|
||||||
|
}
|
||||||
|
} catch (MalformedJsonException e) {
|
||||||
|
throw new JsonSyntaxException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new JsonIOException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,8 +16,10 @@
|
|||||||
package com.google.gson;
|
package com.google.gson;
|
||||||
|
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonToken;
|
||||||
|
import com.google.gson.stream.MalformedJsonException;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
|
||||||
@ -51,8 +53,20 @@ public final class JsonParser {
|
|||||||
* @since 1.3
|
* @since 1.3
|
||||||
*/
|
*/
|
||||||
public JsonElement parse(Reader json) throws JsonIOException, JsonSyntaxException {
|
public JsonElement parse(Reader json) throws JsonIOException, JsonSyntaxException {
|
||||||
|
try {
|
||||||
JsonReader jsonReader = new JsonReader(json);
|
JsonReader jsonReader = new JsonReader(json);
|
||||||
return parse(jsonReader);
|
JsonElement element = parse(jsonReader);
|
||||||
|
if (!element.isJsonNull() && jsonReader.peek() != JsonToken.END_DOCUMENT) {
|
||||||
|
throw new JsonSyntaxException("Did not consume the entire document.");
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
} catch (MalformedJsonException e) {
|
||||||
|
throw new JsonSyntaxException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new JsonIOException(e);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new JsonSyntaxException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user