Fixed MapTest.testInterfaceTypeMapWithSerializer. This test for relying on JsonElement.toString() to have same behavior as gson.toJson(JsonElement). However, gson.toJson() skips nulls by default whereas JsonElement.toString() does not.
This commit is contained in:
parent
b2d5940a9b
commit
cebda2b119
@ -396,14 +396,15 @@ public class MapTest extends TestCase {
|
||||
|
||||
Gson tempGson = new Gson();
|
||||
String subTypeJson = tempGson.toJson(subType);
|
||||
final JsonElement baseTypeJson = tempGson.toJsonTree(subType, TestTypes.Base.class);
|
||||
String expected = "{\"bases\":{\"Test\":" + baseTypeJson.toString() + "},"
|
||||
final JsonElement baseTypeJsonElement = tempGson.toJsonTree(subType, TestTypes.Base.class);
|
||||
String baseTypeJson = tempGson.toJson(baseTypeJsonElement);
|
||||
String expected = "{\"bases\":{\"Test\":" + baseTypeJson + "},"
|
||||
+ "\"subs\":{\"Test\":" + subTypeJson + "}}";
|
||||
|
||||
JsonSerializer<TestTypes.Base> baseTypeAdapter = new JsonSerializer<TestTypes.Base>() {
|
||||
public JsonElement serialize(TestTypes.Base src, Type typeOfSrc,
|
||||
JsonSerializationContext context) {
|
||||
return baseTypeJson;
|
||||
return baseTypeJsonElement;
|
||||
}
|
||||
};
|
||||
|
||||
@ -441,11 +442,11 @@ public class MapTest extends TestCase {
|
||||
private final Map<String, TestTypes.Base> bases = new HashMap<String, TestTypes.Base>();
|
||||
private final Map<String, TestTypes.Sub> subs = new HashMap<String, TestTypes.Sub>();
|
||||
|
||||
public final void addBase(final String name, final TestTypes.Base value) {
|
||||
public final void addBase(String name, TestTypes.Base value) {
|
||||
bases.put(name, value);
|
||||
}
|
||||
|
||||
public final void addSub(final String name, final TestTypes.Sub value) {
|
||||
public final void addSub(String name, TestTypes.Sub value) {
|
||||
subs.put(name, value);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user