11package org .baeldung .gson .serialization ;
22
3- import java .text .ParseException ;
4- import java .text .SimpleDateFormat ;
5- import java .util .Arrays ;
6-
3+ import com .google .gson .Gson ;
4+ import com .google .gson .GsonBuilder ;
5+ import com .google .gson .JsonParser ;
76import org .baeldung .gson .entities .ActorGson ;
87import org .baeldung .gson .entities .Movie ;
98import org .baeldung .gson .entities .MovieWithNullValue ;
10- import org .baeldung .gson .serialization .ActorGsonDeserializer ;
11- import org .baeldung .gson .serialization .ActorGsonSerializer ;
129import org .junit .Assert ;
1310import org .junit .Test ;
1411
15- import com . google . gson . Gson ;
16- import com . google . gson . GsonBuilder ;
17- import com . google . gson . JsonParser ;
12+ import java . text . ParseException ;
13+ import java . text . SimpleDateFormat ;
14+ import java . util . Arrays ;
1815
1916public class GsonSerializeTest {
2017
@@ -40,12 +37,12 @@ public void whenCustomSerialize_thenCorrect() throws ParseException {
4037 MovieWithNullValue movieWithNullValue = new MovieWithNullValue (null , "Mel Gibson" , Arrays .asList (rudyYoungblood ));
4138
4239 String expectedOutput = new GsonBuilder ()
43- .setPrettyPrinting ()
44- .serializeNulls ()
45- .disableHtmlEscaping ()
46- .create ()
47- .toJson (new JsonParser ()
48- .parse ("{\" imdbId\" :null,\" actors\" :[{\" <strong>IMDB Code</strong>\" :\" nm2199632\" ,\" <strong>Date Of Birth</strong>\" :\" 21-09-1982\" ,\" <strong>N° Film:</strong> \" :3,\" filmography\" :\" Apocalypto-Beatdown-Wind Walkers\" }]}" ));
40+ .setPrettyPrinting ()
41+ .serializeNulls ()
42+ .disableHtmlEscaping ()
43+ .create ()
44+ .toJson (new JsonParser ()
45+ .parse ("{\" imdbId\" :null,\" actors\" :[{\" <strong>IMDB Code</strong>\" :\" nm2199632\" ,\" <strong>Date Of Birth</strong>\" :\" 21-09-1982\" ,\" <strong>N° Film:</strong> \" :3,\" filmography\" :\" Apocalypto-Beatdown-Wind Walkers\" }]}" ));
4946 Assert .assertEquals (gson .toJson (movieWithNullValue ), expectedOutput );
5047 }
5148}
0 commit comments