33import com .google .gson .Gson ;
44import com .google .gson .JsonElement ;
55import com .microsoft .graph .logger .ILogger ;
6+ import com .microsoft .graph .models .MessageStub ;
67import com .microsoft .graph .models .ReactionStub ;
78import com .microsoft .graph .models .SubReactionStub1 ;
89import org .junit .jupiter .api .Test ;
910import org .mockito .Mockito ;
1011
1112import static org .junit .jupiter .api .Assertions .assertEquals ;
13+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
1214import static org .junit .jupiter .api .Assertions .assertTrue ;
1315import static org .mockito .Mockito .mock ;
1416
@@ -33,4 +35,33 @@ public void testDeserializationOfObjectWithODataTypeProperty() {
3335 Mockito .verify (reaction .additionalDataManager ()).setAdditionalData (gson .fromJson (testJsonResponse , JsonElement .class ).getAsJsonObject ());
3436 }
3537
38+ @ Test
39+ public void testDefaultSerializerDoesNotIncludeNullValuesByDefault () {
40+ // Given
41+ final String testJsonResponse =
42+ "{\" @odata.type\" : \" #microsoft.graph.messageStub\" , \" body\" : null}" ;
43+
44+ // When
45+ final MessageStub message = defaultSerializer .deserializeObject (testJsonResponse , MessageStub .class );
46+
47+ // Then
48+ assertNotNull (message );
49+ assertEquals ("{}" , defaultSerializer .serializeObject (message ));
50+ }
51+
52+ @ Test
53+ public void testDefaultNullSerializerDoesIncludeNullValues () {
54+ // Given
55+ final String testJsonResponse =
56+ "{\" @odata.type\" : \" #microsoft.graph.messageStub\" ,\" body\" :null}" ;
57+
58+ // When
59+ final DefaultSerializer nullSerializer = new DefaultSerializer (logger , true );
60+ final MessageStub message = nullSerializer .deserializeObject (testJsonResponse , MessageStub .class );
61+
62+ // Then
63+ assertNotNull (message );
64+ assertEquals ("{\" body\" :null,\" reaction\" :null}" , nullSerializer .serializeObject (message ));
65+ }
66+
3667}
0 commit comments