Skip to content

Commit 61d5640

Browse files
committed
- fixes static analysis errors as example
1 parent 6aba30d commit 61d5640

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private CollectionResponseSerializer() {}
5656
@SuppressWarnings("unchecked")
5757
@Nullable
5858
public static <T1> BaseCollectionResponse<T1> deserialize(@Nonnull final JsonElement json, @Nonnull final Type typeOfT, @Nonnull final ILogger logger) throws JsonParseException {
59-
if (json == null || !json.isJsonObject()| !typeOfT.getClass().equals(Class.class)) {
59+
if (json == null || !json.isJsonObject() || !typeOfT.getClass().equals(Class.class)) {
6060
return null;
6161
}
6262
serializer = new DefaultSerializer(logger);
@@ -86,8 +86,13 @@ public static <T1> BaseCollectionResponse<T1> deserialize(@Nonnull final JsonEle
8686
if(sourceElement.isJsonObject()) {
8787
final JsonObject sourceObject = sourceElement.getAsJsonObject();
8888
Class<?> entityClass = serializer.getDerivedClass(sourceObject, baseEntityClass);
89-
if(entityClass == null && baseEntityClass != null)
90-
entityClass = baseEntityClass; // it is possible the odata type is absent or we can't find the derived type (not in SDK yet)
89+
if(entityClass == null) {
90+
if(baseEntityClass == null) {
91+
logger.logError("Could not find target class for object " + sourceObject.toString(), null);
92+
continue;
93+
} else
94+
entityClass = baseEntityClass; // it is possible the odata type is absent or we can't find the derived type (not in SDK yet)
95+
}
9196
final T1 targetObject = (T1)serializer.deserializeObject(sourceObject, entityClass);
9297
((IJsonBackedObject)targetObject).setRawObject(serializer, sourceObject);
9398
list.add(targetObject);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ private void addAdditionalDataFromManagerToJson(AdditionalDataManager additional
352352
* @return the derived class if found, or null if not applicable
353353
*/
354354
@Nullable
355-
public Class<?> getDerivedClass(@Nonnull final JsonObject jsonObject, @Nonnull final Class<?> parentClass) {
355+
public Class<?> getDerivedClass(@Nonnull final JsonObject jsonObject, @Nullable final Class<?> parentClass) {
356356
//Identify the odata.type information if provided
357357
if (jsonObject.get(ODATA_TYPE_KEY) != null) {
358358
/** #microsoft.graph.user or #microsoft.graph.callrecords.callrecord */

0 commit comments

Comments
 (0)