Skip to content

Commit 21af7e7

Browse files
committed
- fixes an issue where passing an array would make the deserializer fail
1 parent 06139de commit 21af7e7

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,29 @@ public <T> T deserializeObject(final String inputString, final Class<T> clazz, M
8484
// Populate the JSON-backed fields for any annotations that are not in the object model
8585
if (jsonObject instanceof IJsonBackedObject) {
8686
logger.logDebug("Deserializing type " + clazz.getSimpleName());
87-
final JsonObject rawObject = gson.fromJson(inputString, JsonObject.class);
87+
final JsonElement rawElement = gson.fromJson(inputString, JsonElement.class);
88+
final JsonObject rawObject = rawElement.isJsonObject() ? rawElement.getAsJsonObject() : null;
8889

8990
// If there is a derived class, try to get it and deserialize to it
90-
Class<?> derivedClass = this.getDerivedClass(rawObject, clazz);
91-
final T jo;
92-
if (derivedClass != null) {
93-
jo = (T) gson.fromJson(inputString, derivedClass);
94-
} else {
95-
jo = jsonObject;
91+
T jo = jsonObject;
92+
if (rawElement.isJsonObject()) {
93+
final Class<?> derivedClass = this.getDerivedClass(rawObject, clazz);
94+
if(derivedClass != null)
95+
jo = (T) gson.fromJson(inputString, derivedClass);
9696
}
9797

9898
final IJsonBackedObject jsonBackedObject = (IJsonBackedObject) jo;
99-
jsonBackedObject.setRawObject(this, rawObject);
99+
100+
if(rawElement.isJsonObject()) {
101+
jsonBackedObject.setRawObject(this, rawObject);
102+
jsonBackedObject.additionalDataManager().setAdditionalData(rawObject);
103+
setChildAdditionalData(jsonBackedObject,rawObject);
104+
}
100105

101106
if (responseHeaders != null) {
102107
JsonElement convertedHeaders = gson.toJsonTree(responseHeaders);
103108
jsonBackedObject.additionalDataManager().put(graphResponseHeadersKey, convertedHeaders);
104109
}
105-
106-
jsonBackedObject.additionalDataManager().setAdditionalData(rawObject);
107-
setChildAdditionalData(jsonBackedObject,rawObject);
108110
return jo;
109111
} else {
110112
logger.logDebug("Deserializing a non-IJsonBackedObject type " + clazz.getSimpleName());

0 commit comments

Comments
 (0)