Skip to content

Commit 0f3fb83

Browse files
committed
- pr feedback
1 parent 98e44d9 commit 0f3fb83

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

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

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -237,59 +237,59 @@ public <T> String serializeObject(@Nonnull final T serializableObject) {
237237
* @param outJson the serialized output JSON to add to
238238
*/
239239
@SuppressWarnings("unchecked")
240-
private void getChildAdditionalData(final Object serializableObject, final JsonElement outJson) {
241-
if(outJson == null || serializableObject == null || !outJson.isJsonObject())
242-
return;
240+
private void getChildAdditionalData(final Object serializableObject, final JsonElement outJson) {
241+
if(outJson == null || serializableObject == null || !outJson.isJsonObject())
242+
return;
243243
final JsonObject outJsonObject = outJson.getAsJsonObject();
244-
// Use reflection to iterate through fields for eligible Graph children
245-
for (java.lang.reflect.Field field : serializableObject.getClass().getFields()) {
246-
try {
247-
final Object fieldObject = field.get(serializableObject);
248-
final JsonElement fieldJsonElement = outJsonObject.get(field.getName());
249-
if(fieldObject == null || fieldJsonElement == null)
250-
continue;
244+
// Use reflection to iterate through fields for eligible Graph children
245+
for (java.lang.reflect.Field field : serializableObject.getClass().getFields()) {
246+
try {
247+
final Object fieldObject = field.get(serializableObject);
248+
final JsonElement fieldJsonElement = outJsonObject.get(field.getName());
249+
if(fieldObject == null || fieldJsonElement == null)
250+
continue;
251251

252-
// If the object is a HashMap, iterate through its children
253-
if (fieldObject instanceof Map && fieldJsonElement.isJsonObject()) {
254-
final Map<String, Object> serializableChildren = (Map<String, Object>) fieldObject;
255-
final Iterator<Entry<String, Object>> it = serializableChildren.entrySet().iterator();
256-
final JsonObject fieldJsonObject = fieldJsonElement.getAsJsonObject();
252+
// If the object is a HashMap, iterate through its children
253+
if (fieldObject instanceof Map && fieldJsonElement.isJsonObject()) {
254+
final Map<String, Object> serializableChildren = (Map<String, Object>) fieldObject;
255+
final Iterator<Entry<String, Object>> it = serializableChildren.entrySet().iterator();
256+
final JsonObject fieldJsonObject = fieldJsonElement.getAsJsonObject();
257257

258-
while (it.hasNext()) {
259-
final Map.Entry<String, Object> pair = (Map.Entry<String, Object>)it.next();
260-
final Object child = pair.getValue();
261-
final JsonElement childJsonElement = fieldJsonObject.get(pair.getKey().toString());
262-
// If the item is a valid Graph object, add its additional data
263-
getChildAdditionalData(child, childJsonElement);
264-
}
265-
}
266-
// If the object is a list of Graph objects, iterate through elements
267-
else if (fieldObject instanceof List && fieldJsonElement.isJsonArray()) {
268-
final JsonArray fieldArrayValue = fieldJsonElement.getAsJsonArray();
269-
final List<?> fieldObjectList = (List<?>) fieldObject;
270-
for (int index = 0; index < fieldObjectList.size(); index++) {
271-
final Object item = fieldObjectList.get(index);
272-
final JsonElement itemJsonElement = fieldArrayValue.get(index);
273-
getChildAdditionalData(item, itemJsonElement);
274-
}
275-
} else if(fieldJsonElement.isJsonObject()) {
258+
while (it.hasNext()) {
259+
final Map.Entry<String, Object> pair = (Map.Entry<String, Object>)it.next();
260+
final Object child = pair.getValue();
261+
final JsonElement childJsonElement = fieldJsonObject.get(pair.getKey().toString());
262+
// If the item is a valid Graph object, add its additional data
263+
getChildAdditionalData(child, childJsonElement);
264+
}
265+
}
266+
// If the object is a list of Graph objects, iterate through elements
267+
else if (fieldObject instanceof List && fieldJsonElement.isJsonArray()) {
268+
final JsonArray fieldArrayValue = fieldJsonElement.getAsJsonArray();
269+
final List<?> fieldObjectList = (List<?>) fieldObject;
270+
for (int index = 0; index < fieldObjectList.size(); index++) {
271+
final Object item = fieldObjectList.get(index);
272+
final JsonElement itemJsonElement = fieldArrayValue.get(index);
273+
getChildAdditionalData(item, itemJsonElement);
274+
}
275+
} else if(fieldJsonElement.isJsonObject()) {
276276
// If the object is a valid Graph object, add its additional data
277-
final JsonObject fieldJsonObject = fieldJsonElement.getAsJsonObject();
278-
addAdditionalDataFromJsonElementToJson(fieldObject, fieldJsonObject);
277+
final JsonObject fieldJsonObject = fieldJsonElement.getAsJsonObject();
278+
addAdditionalDataFromJsonObjectToJson(fieldObject, fieldJsonObject);
279279
}
280-
} catch (IllegalArgumentException | IllegalAccessException e) {
281-
logger.logError("Unable to access child fields of " + serializableObject.getClass().getSimpleName(), e);
282-
}
283-
}
284-
}
280+
} catch (IllegalArgumentException | IllegalAccessException e) {
281+
logger.logError("Unable to access child fields of " + serializableObject.getClass().getSimpleName(), e);
282+
}
283+
}
284+
}
285285

286286
/**
287287
* Add each non-transient additional data property to the given JSON node
288288
*
289289
* @param item the object containing additional data
290290
* @param itemJsonObject the JSON node to add the additional data properties to
291291
*/
292-
private void addAdditionalDataFromJsonElementToJson (final Object item, final JsonObject itemJsonObject) {
292+
private void addAdditionalDataFromJsonObjectToJson (final Object item, final JsonObject itemJsonObject) {
293293
if (item instanceof IJsonBackedObject && itemJsonObject != null) {
294294
final IJsonBackedObject serializableItem = (IJsonBackedObject) item;
295295
final AdditionalDataManager itemAdditionalData = serializableItem.additionalDataManager();

src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void usesHttpMethodFromRequestIfAlreadySet() throws MalformedURLException {
179179
void doesNotThrowWhenTryingToRemoveRequestFromNull() {
180180
final BatchRequestContent batchRequest = new BatchRequestContent();
181181
batchRequest.removeBatchRequestStepWithId("id");
182-
assertEquals(0, batchRequest.requests.size());
182+
assertNull(batchRequest.requests);
183183
}
184184

185185
@Test

0 commit comments

Comments
 (0)