Minor fixes.
This commit is contained in:
parent
60ef777efc
commit
de6af4411b
|
@ -185,7 +185,7 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
|
|||
start(objTypePair);
|
||||
try {
|
||||
JsonElement element =
|
||||
serializer.serialize(objTypePair.getObject(), objTypePair.getType(), context);
|
||||
serializer.serialize(objTypePair.getObject(), objTypePair.getType(), context);
|
||||
return element == null ? JsonNull.createJsonNull() : element;
|
||||
} finally {
|
||||
end(objTypePair);
|
||||
|
|
|
@ -16,10 +16,6 @@
|
|||
|
||||
package com.google.gson.functional;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
|
@ -34,6 +30,10 @@ import com.google.gson.common.TestTypes.ClassWithBaseField;
|
|||
import com.google.gson.common.TestTypes.Sub;
|
||||
import com.google.gson.common.TestTypes.SubSerializer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* Functional Test exercising custom serialization only. When test applies to both
|
||||
* serialization and deserialization then add it to CustomTypeAdapterTest.
|
||||
|
@ -44,9 +44,9 @@ public class CustomSerializerTest extends TestCase {
|
|||
|
||||
public void testBaseClassSerializerInvokedForBaseClassFields() {
|
||||
Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(Base.class, new BaseSerializer())
|
||||
.registerTypeAdapter(Sub.class, new SubSerializer())
|
||||
.create();
|
||||
.registerTypeAdapter(Base.class, new BaseSerializer())
|
||||
.registerTypeAdapter(Sub.class, new SubSerializer())
|
||||
.create();
|
||||
ClassWithBaseField target = new ClassWithBaseField(new Base());
|
||||
JsonObject json = (JsonObject) gson.toJsonTree(target);
|
||||
JsonObject base = json.get("base").getAsJsonObject();
|
||||
|
@ -55,9 +55,9 @@ public class CustomSerializerTest extends TestCase {
|
|||
|
||||
public void testSubClassSerializerInvokedForBaseClassFieldsHoldingSubClassInstances() {
|
||||
Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(Base.class, new BaseSerializer())
|
||||
.registerTypeAdapter(Sub.class, new SubSerializer())
|
||||
.create();
|
||||
.registerTypeAdapter(Base.class, new BaseSerializer())
|
||||
.registerTypeAdapter(Sub.class, new SubSerializer())
|
||||
.create();
|
||||
ClassWithBaseField target = new ClassWithBaseField(new Sub());
|
||||
JsonObject json = (JsonObject) gson.toJsonTree(target);
|
||||
JsonObject base = json.get("base").getAsJsonObject();
|
||||
|
@ -66,9 +66,9 @@ public class CustomSerializerTest extends TestCase {
|
|||
|
||||
public void testSubClassSerializerInvokedForBaseClassFieldsHoldingArrayOfSubClassInstances() {
|
||||
Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(Base.class, new BaseSerializer())
|
||||
.registerTypeAdapter(Sub.class, new SubSerializer())
|
||||
.create();
|
||||
.registerTypeAdapter(Base.class, new BaseSerializer())
|
||||
.registerTypeAdapter(Sub.class, new SubSerializer())
|
||||
.create();
|
||||
ClassWithBaseArrayField target = new ClassWithBaseArrayField(new Base[] {new Sub(), new Sub()});
|
||||
JsonObject json = (JsonObject) gson.toJsonTree(target);
|
||||
JsonArray array = json.get("base").getAsJsonArray();
|
||||
|
@ -80,8 +80,8 @@ public class CustomSerializerTest extends TestCase {
|
|||
|
||||
public void testBaseClassSerializerInvokedForBaseClassFieldsHoldingSubClassInstances() {
|
||||
Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(Base.class, new BaseSerializer())
|
||||
.create();
|
||||
.registerTypeAdapter(Base.class, new BaseSerializer())
|
||||
.create();
|
||||
ClassWithBaseField target = new ClassWithBaseField(new Sub());
|
||||
JsonObject json = (JsonObject) gson.toJsonTree(target);
|
||||
JsonObject base = json.get("base").getAsJsonObject();
|
||||
|
@ -97,7 +97,6 @@ public class CustomSerializerTest extends TestCase {
|
|||
})
|
||||
.create();
|
||||
JsonElement json = gson.toJsonTree(new Base());
|
||||
System.out.println(json);
|
||||
assertTrue(json.isJsonNull());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user