Skip to content

Commit b4ecc09

Browse files
author
FAREAST\vidadhee
committed
Added a test case to verify multi-level additional data setter and added a comment to explain the IllegalArgumentException
1 parent b4e92cb commit b4ecc09

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ else if (fieldObject != null && fieldObject instanceof IJsonBackedObject) {
148148
setChildAdditionalData((IJsonBackedObject) fieldObject,rawJson.get(field.getName()).getAsJsonObject());
149149
}
150150
} catch (IllegalArgumentException | IllegalAccessException e) {
151-
logger.logError("Unable to access child fields of " + serializedObject.getClass().getSimpleName(), e);
151+
//Not throwing the IllegalArgumentException as the Serialized Object would still be usable even if the additional data is not set.
152+
logger.logError("Unable to set child fields of " + serializedObject.getClass().getSimpleName(), e);
152153
}
153154
}
154155
}

src/test/java/com/microsoft/graph/serializer/AdditionalDataTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import org.junit.Before;
66
import org.junit.Test;
77

8+
import com.google.gson.JsonElement;
89
import com.google.gson.JsonPrimitive;
910
import com.microsoft.graph.logger.DefaultLogger;
11+
import com.microsoft.graph.models.extensions.Drive;
1012
import com.microsoft.graph.models.extensions.Entity;
1113
import com.microsoft.graph.models.extensions.PlannerAssignment;
1214
import com.microsoft.graph.models.extensions.PlannerAssignments;
@@ -48,6 +50,15 @@ public void testChildAdditionalData() {
4850

4951
assertEquals("{\"manager\":{\"id\":\"1\",\"additionalData\":\"additionalValue\"},\"id\":\"2\"}", serializedObject);
5052
}
53+
54+
@Test
55+
public void testChildAdditionalDataDeserialization() {
56+
String source = "{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#drives/$entity\",\"id\":\"8bf6ae90006c4a4c\",\"driveType\":\"personal\",\"owner\":{\"user\":{\"displayName\":\"Peter\",\"id\":\"8bf6ae90006c4a4c\",\"email\":\"[email protected]\"}},\"quota\":{\"deleted\":1485718314,\"remaining\":983887466461,\"state\":\"normal\",\"total\":1142461300736,\"used\":158573834275}}";
57+
Drive result = serializer.deserializeObject(source, Drive.class);
58+
JsonElement email = result.owner.user.additionalDataManager().get("email");
59+
60+
assertEquals("\"[email protected]\"",email.toString());
61+
}
5162

5263
@Test
5364
public void testSkipTransientData() {

0 commit comments

Comments
 (0)