From 9f5a2086deafa340ac12e78d44c8c23b19483f9d Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Tue, 14 Oct 2008 19:37:33 +0000 Subject: [PATCH] updated Gson version to 1.2.2 Added a test to ensure that CustomTypeAdapters are not applied automatically for SubClasses. --- gson/pom.xml | 2 +- .../functional/CustomTypeAdaptersTest.java | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gson/pom.xml b/gson/pom.xml index d3588fff..096e3171 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -4,7 +4,7 @@ com.google.code.gson gson jar - 1.2.1 + 1.2.2 2008 Gson http://code.google.com/p/google-gson/ diff --git a/gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java b/gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java index 42a9c6f1..79ddb246 100644 --- a/gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java +++ b/gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java @@ -125,7 +125,23 @@ public class CustomTypeAdaptersTest extends TestCase { assertEquals(7, target.getBag().getIntValue()); } - public void testCustomTypeAdapterAppliesToSubClasses() { + public void testCustomTypeAdapterDoesNotAppliesToSubClasses() { + Gson gson = new GsonBuilder().registerTypeAdapter(Base.class, new JsonSerializer () { + public JsonElement serialize(Base src, Type typeOfSrc, JsonSerializationContext context) { + JsonObject json = new JsonObject(); + json.addProperty("value", src.baseValue); + return json; + } + }).create(); + Base b = new Base(); + String json = gson.toJson(b); + assertTrue(json.contains("value")); + b = new Derived(); + json = gson.toJson(b); + assertTrue(json.contains("derivedValue")); + } + + public void testCustomTypeAdapterAppliesToSubClassesSerializedAsBaseClass() { Gson gson = new GsonBuilder().registerTypeAdapter(Base.class, new JsonSerializer () { public JsonElement serialize(Base src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject();