From 323dfa0af5401130de9f4278593fcacb9e5cda1c Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Sun, 1 Jan 2012 12:36:42 +0000 Subject: [PATCH] Be strict in TypeAdapter's toJson/fromJson methods --- gson/src/main/java/com/google/gson/TypeAdapter.java | 3 --- gson/src/test/java/com/google/gson/ObjectTypeAdapterTest.java | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/gson/src/main/java/com/google/gson/TypeAdapter.java b/gson/src/main/java/com/google/gson/TypeAdapter.java index 9426edf7..58dd6424 100644 --- a/gson/src/main/java/com/google/gson/TypeAdapter.java +++ b/gson/src/main/java/com/google/gson/TypeAdapter.java @@ -227,7 +227,6 @@ public abstract class TypeAdapter { public final JsonElement toJsonTree(T value) { try { JsonTreeWriter jsonWriter = new JsonTreeWriter(); - jsonWriter.setLenient(true); write(jsonWriter, value); return jsonWriter.get(); } catch (IOException e) { @@ -254,7 +253,6 @@ public abstract class TypeAdapter { */ public final T fromJson(Reader in) throws IOException { JsonReader reader = new JsonReader(in); - reader.setLenient(true); // TODO: non-lenient? return read(reader); } @@ -280,7 +278,6 @@ public abstract class TypeAdapter { public final T fromJsonTree(JsonElement jsonTree) { try { JsonReader jsonReader = new JsonTreeReader(jsonTree); - jsonReader.setLenient(true); return read(jsonReader); } catch (IOException e) { throw new JsonIOException(e); diff --git a/gson/src/test/java/com/google/gson/ObjectTypeAdapterTest.java b/gson/src/test/java/com/google/gson/ObjectTypeAdapterTest.java index b5e800d7..65798dd7 100644 --- a/gson/src/test/java/com/google/gson/ObjectTypeAdapterTest.java +++ b/gson/src/test/java/com/google/gson/ObjectTypeAdapterTest.java @@ -26,7 +26,7 @@ public final class ObjectTypeAdapterTest extends TestCase { private final TypeAdapter adapter = gson.getAdapter(Object.class); public void testDeserialize() throws Exception { - Map map = (Map) adapter.fromJson("{a: 5, b: [1, 2, null], c: {x: y}}"); + Map map = (Map) adapter.fromJson("{\"a\":5,\"b\":[1,2,null],\"c\":{\"x\":\"y\"}}"); assertEquals(5.0, map.get("a")); assertEquals(Arrays.asList(1.0, 2.0, null), map.get("b")); assertEquals(Collections.singletonMap("x", "y"), map.get("c"));