updated Gson version to 1.2.2

Added a test to ensure that CustomTypeAdapters are not applied automatically
for SubClasses.
This commit is contained in:
Inderjeet Singh 2008-10-14 19:37:33 +00:00
parent 745c8e2a83
commit 9f5a2086de
2 changed files with 18 additions and 2 deletions

View File

@ -4,7 +4,7 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<packaging>jar</packaging>
<version>1.2.1</version>
<version>1.2.2</version>
<inceptionYear>2008</inceptionYear>
<name>Gson</name>
<url>http://code.google.com/p/google-gson/</url>

View File

@ -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<Base> () {
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<Base> () {
public JsonElement serialize(Base src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject();