@@ -33,9 +33,7 @@ public void givenArrayOfObjects_whenSerializing_thenCorrect() {
3333 @ Test
3434 public void givenCollection_whenSerializing_thenCorrect () {
3535 final Collection <SourceClass > sourceCollection = Lists .newArrayList (new SourceClass (1 , "one" ), new SourceClass (2 , "two" ));
36- final Type sourceCollectionType = new TypeToken <Collection <SourceClass >>() {
37- }.getType ();
38- final String jsonCollection = new Gson ().toJson (sourceCollection , sourceCollectionType );
36+ final String jsonCollection = new Gson ().toJson (sourceCollection );
3937
4038 final String expectedResult = "[{\" intValue\" :1,\" stringValue\" :\" one\" },{\" intValue\" :2,\" stringValue\" :\" two\" }]" ;
4139 assertEquals (expectedResult , jsonCollection );
@@ -63,19 +61,6 @@ public void givenIgnoringAField_whenSerializingWithCustomSerializer_thenFieldIgn
6361 assertEquals (expectedResult , jsonString );
6462 }
6563
66- @ Test
67- public void givenDate_whenSerializing_thenCorrect () {
68- final Date sourceDate = new Date (1000000L );
69- final Gson gson = new Gson ();
70- final Type sourceDateType = new TypeToken <Date >() {
71- }.getType ();
72- String jsonDate = gson .toJson (sourceDate , sourceDateType );
73-
74- System .out .println ("jsonDate:\n " + jsonDate );
75- final String expectedResult = "\" Jan 1, 1970 3:16:40 AM\" " ;
76- assertTrue (jsonDate .equals (expectedResult ));
77- }
78-
7964 @ Test
8065 public void givenUsingCustomDeserializer_whenFieldNotMatchesCriteria_thenIgnored () {
8166 final SourceClass sourceObject = new SourceClass (-1 , "minus 1" );
@@ -84,10 +69,23 @@ public void givenUsingCustomDeserializer_whenFieldNotMatchesCriteria_thenIgnored
8469 final Gson gson = gsonBuildr .create ();
8570 final Type sourceObjectType = new TypeToken <SourceClass >() {
8671 }.getType ();
87- String jsonString = gson .toJson (sourceObject , sourceObjectType );
72+ final String jsonString = gson .toJson (sourceObject , sourceObjectType );
8873
8974 final String expectedResult = "{\" stringValue\" :\" minus 1\" }" ;
9075 assertEquals (expectedResult , jsonString );
9176 }
9277
78+ @ Test
79+ public void givenDate_whenSerializing_thenCorrect () {
80+ final Date sourceDate = new Date (1000000L );
81+ final Gson gson = new Gson ();
82+ final Type sourceDateType = new TypeToken <Date >() {
83+ }.getType ();
84+ final String jsonDate = gson .toJson (sourceDate , sourceDateType );
85+
86+ System .out .println ("jsonDate:\n " + jsonDate );
87+ final String expectedResult = "\" Jan 1, 1970 3:16:40 AM\" " ;
88+ assertTrue (jsonDate .equals (expectedResult ));
89+ }
90+
9391}
0 commit comments