Add new tests with SerializedName annotation that contains a space in the name.

This commit is contained in:
Joel Leitch 2010-05-28 02:13:11 +00:00
parent 855a79a0f0
commit 9cd72ca7fb
2 changed files with 7 additions and 5 deletions

View File

@ -395,16 +395,18 @@ public class TestTypes {
public static class ClassWithSerializedNameFields {
@SerializedName("fooBar") public final int f;
@SerializedName("Another Foo") public final int g;
public ClassWithSerializedNameFields() {
this(1);
this(1, 4);
}
public ClassWithSerializedNameFields(int f) {
public ClassWithSerializedNameFields(int f, int g) {
this.f = f;
this.g = g;
}
public String getExpectedJson() {
return '{' + "\"fooBar\":" + f + '}';
return '{' + "\"fooBar\":" + f + ",\"Another Foo\":" + g + '}';
}
}

View File

@ -89,14 +89,14 @@ public class NamingPolicyTest extends TestCase {
public void testGsonWithSerializedNameFieldNamingPolicySerialization() {
Gson gson = builder.create();
ClassWithSerializedNameFields expected = new ClassWithSerializedNameFields(5);
ClassWithSerializedNameFields expected = new ClassWithSerializedNameFields(5, 6);
String actual = gson.toJson(expected);
assertEquals(expected.getExpectedJson(), actual);
}
public void testGsonWithSerializedNameFieldNamingPolicyDeserialization() {
Gson gson = builder.create();
ClassWithSerializedNameFields expected = new ClassWithSerializedNameFields(5);
ClassWithSerializedNameFields expected = new ClassWithSerializedNameFields(5, 7);
ClassWithSerializedNameFields actual =
gson.fromJson(expected.getExpectedJson(), ClassWithSerializedNameFields.class);
assertEquals(expected.f, actual.f);