44import static org .junit .Assert .assertTrue ;
55
66import java .lang .reflect .Type ;
7+ import java .util .Calendar ;
78import java .util .Collection ;
89import java .util .Date ;
10+ import java .util .GregorianCalendar ;
911
1012import org .baeldung .gson .serialization .DifferentNameSerializer ;
1113import org .baeldung .gson .serialization .IgnoringFieldsNotMatchingCriteriaSerializer ;
1214import org .baeldung .gson .serialization .IgnoringFieldsSerializer ;
1315import org .baeldung .gson .serialization .SourceClass ;
16+ import org .joda .time .DateTime ;
1417import org .junit .Test ;
1518
1619import com .google .common .collect .Lists ;
@@ -77,15 +80,16 @@ public void givenUsingCustomDeserializer_whenFieldNotMatchesCriteria_thenIgnored
7780
7881 @ Test
7982 public void givenDate_whenSerializing_thenCorrect () {
80- final Date sourceDate = new Date (1000000L );
83+ Date sourceDate = new DateTime ().withYear (2000 ).withMonthOfYear (1 ).withDayOfMonth (1 ).withHourOfDay (0 ).withMinuteOfHour (0 ).withSecondOfMinute (0 ).toDate ();
84+
8185 final Gson gson = new Gson ();
82- final Type sourceDateType = new TypeToken <Date >() {
86+ Type sourceDateType = new TypeToken <Date >() {
8387 }.getType ();
84- final String jsonDate = gson .toJson (sourceDate , sourceDateType );
88+ String jsonDate = gson .toJson (sourceDate , sourceDateType );
8589
8690 System .out .println ("jsonDate:\n " + jsonDate );
87- final String expectedResult = "\" Jan 1, 1970 3:16:40 AM\" " ;
88- assertTrue ( jsonDate . equals ( expectedResult ) );
91+ String expectedResult = "\" Jan 1, 2000 12:00:00 AM\" " ;
92+ assertEquals ( expectedResult , jsonDate );
8993 }
9094
9195}
0 commit comments