Skip to content

Commit dec98ba

Browse files
committed
- removes extensions and generated additional namespaces in reflection
1 parent bb5c91e commit dec98ba

2 files changed

Lines changed: 27 additions & 30 deletions

File tree

‎src/main/java/com/microsoft/graph/serializer/CollectionPageSerializer.java‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public class CollectionPageSerializer {
5252
private final static Integer collectionLength = 10;
5353
/** length of the work "response" */
5454
private final static Integer responseLength = 8;
55-
/** the extensions segment in the package name of target classes */
56-
private final static String extensionsPath = "extensions.";
5755

5856
/**
5957
* Not available for instantiation
@@ -109,9 +107,9 @@ public static <T1, T2 extends BaseRequestBuilder<T1>> BaseCollectionPage<T1, T2>
109107
serializer = new DefaultSerializer(logger);
110108
final JsonArray sourceArray = json.getAsJsonArray();
111109
final ArrayList<T1> list = new ArrayList<T1>(sourceArray.size());
112-
/** eg: com.microsoft.graph.requests.extensions.AttachmentCollectionPage */
110+
/** eg: com.microsoft.graph.requests.AttachmentCollectionPage */
113111
final String collectionPageClassCanonicalName = ((Class<?>)typeOfT).getName();
114-
/** eg: com.microsoft.graph.models.extensions.Attachment */
112+
/** eg: com.microsoft.graph.models.Attachment */
115113
final String baseEntityClassCanonicalName = collectionPageClassCanonicalName
116114
.substring(0, collectionPageClassCanonicalName.length() - pageLength - collectionLength)
117115
.replace("requests", "models");
@@ -128,17 +126,16 @@ public static <T1, T2 extends BaseRequestBuilder<T1>> BaseCollectionPage<T1, T2>
128126
list.add(targetObject);
129127
}
130128
}
131-
/** eg: com.microsoft.graph.requests.extensions.AttachmentCollectionResponse */
129+
/** eg: com.microsoft.graph.requests.AttachmentCollectionResponse */
132130
final String responseClassCanonicalName = collectionPageClassCanonicalName
133131
.substring(0, collectionPageClassCanonicalName.length() - pageLength) + "Response";
134132
final Class<?> responseClass = Class.forName(responseClassCanonicalName);
135133
final Object response = responseClass.getConstructor().newInstance();
136134
responseClass.getField("value").set(response, list);
137135
final Class<?> collectionPageClass = Class.forName(collectionPageClassCanonicalName);
138-
/** eg: com.microsoft.graph.requests.extensions.AttachmentCollectionRequestBuilder */
136+
/** eg: com.microsoft.graph.requests.AttachmentCollectionRequestBuilder */
139137
final String responseBuilderCanonicalName = responseClassCanonicalName
140-
.substring(0, responseClassCanonicalName.length() - responseLength)
141-
.replace(extensionsPath, extensionsPath) + "RequestBuilder";
138+
.substring(0, responseClassCanonicalName.length() - responseLength) + "RequestBuilder";
142139
final Class<?> responseBuilderClass = Class.forName(responseBuilderCanonicalName);
143140
return (BaseCollectionPage<T1, T2>)collectionPageClass.getConstructor(responseClass, responseBuilderClass).newInstance(response, null);
144141
} catch(ClassNotFoundException ex) {

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// ------------------------------------------------------------------------------
22
// Copyright (c) 2017 Microsoft Corporation
3-
//
3+
//
44
// Permission is hereby granted, free of charge, to any person obtaining a copy
55
// of this software and associated documentation files (the "Software"), to deal
66
// in the Software without restriction, including without limitation the rights
77
// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
88
// copies of the Software, and to permit persons to whom the Software is
99
// furnished to do so, subject to the following conditions:
10-
//
10+
//
1111
// The above copyright notice and this permission notice shall be included in
1212
// all copies or substantial portions of the Software.
13-
//
13+
//
1414
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1515
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1616
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -101,7 +101,7 @@ public <T> T deserializeObject(@Nonnull final String inputString, @Nonnull final
101101
}
102102

103103
final IJsonBackedObject jsonBackedObject = (IJsonBackedObject) jo;
104-
104+
105105
if(rawElement.isJsonObject()) {
106106
jsonBackedObject.setRawObject(this, rawObject);
107107
jsonBackedObject.additionalDataManager().setAdditionalData(rawObject);
@@ -146,7 +146,7 @@ private void setChildAdditionalData(final IJsonBackedObject serializedObject, fi
146146
if (child instanceof IJsonBackedObject) {
147147
final AdditionalDataManager childAdditionalDataManager = ((IJsonBackedObject) child).additionalDataManager();
148148
final JsonElement fieldElement = rawJson.get(field.getName());
149-
if(fieldElement != null && fieldElement.isJsonObject()
149+
if(fieldElement != null && fieldElement.isJsonObject()
150150
&& fieldElement.getAsJsonObject().get(pair.getKey()) != null
151151
&& fieldElement.getAsJsonObject().get(pair.getKey()).isJsonObject()) {
152152
childAdditionalDataManager.setAdditionalData(fieldElement.getAsJsonObject().get(pair.getKey()).getAsJsonObject());
@@ -172,7 +172,7 @@ else if (fieldObject instanceof List) {
172172
}
173173
}
174174
}
175-
if (rawJsonArraySize != fieldObjectListSize)
175+
if (rawJsonArraySize != fieldObjectListSize)
176176
logger.logDebug("rawJsonArray has a size of " + rawJsonArraySize + " and fieldObjectList of " + fieldObjectListSize);
177177
}
178178
}
@@ -195,7 +195,7 @@ else if (fieldObject instanceof IJsonBackedObject) {
195195
}
196196
}
197197
}
198-
198+
199199
/**
200200
* Serializes an object into a string
201201
*
@@ -237,23 +237,23 @@ public <T> String serializeObject(@Nonnull final T serializableObject) {
237237
private <T> JsonElement getDataFromAdditionalDataManager(JsonElement outJsonTree, final T serializableObject) {
238238
final IJsonBackedObject serializableJsonObject = (IJsonBackedObject) serializableObject;
239239
final AdditionalDataManager additionalData = serializableJsonObject.additionalDataManager();
240-
240+
241241
// If the item is a valid Graph object, add its additional data
242242
if (outJsonTree.isJsonObject()) {
243243
final JsonObject outJson = outJsonTree.getAsJsonObject();
244-
244+
245245
addAdditionalDataFromManagerToJson(additionalData, outJson);
246246
getChildAdditionalData(serializableJsonObject, outJson);
247-
247+
248248
return outJson;
249249
} else {
250250
return outJsonTree;
251251
}
252252
}
253-
253+
254254
/**
255255
* Recursively populates additional data for each child object
256-
*
256+
*
257257
* @param serializableObject the child to get additional data for
258258
* @param outJson the serialized output JSON to add to
259259
*/
@@ -268,13 +268,13 @@ private void getChildAdditionalData(final IJsonBackedObject serializableObject,
268268
final JsonElement fieldJsonElement = outJson.get(field.getName());
269269
if(fieldObject == null || field == null || fieldJsonElement == null)
270270
continue;
271-
271+
272272
// If the object is a HashMap, iterate through its children
273273
if (fieldObject instanceof Map && fieldJsonElement.isJsonObject()) {
274274
final Map<String, Object> serializableChildren = (Map<String, Object>) fieldObject;
275275
final Iterator<Entry<String, Object>> it = serializableChildren.entrySet().iterator();
276276
final JsonObject fieldJsonObject = fieldJsonElement.getAsJsonObject();
277-
277+
278278
while (it.hasNext()) {
279279
final Map.Entry<String, Object> pair = (Map.Entry<String, Object>)it.next();
280280
final Object child = pair.getValue();
@@ -303,7 +303,7 @@ else if (fieldObject instanceof List && fieldJsonElement.isJsonArray()) {
303303

304304
/**
305305
* Add each non-transient additional data property to the given JSON node
306-
*
306+
*
307307
* @param item the object containing additional data
308308
* @param itemJsonElement the JSON node to add the additional data properties to
309309
*/
@@ -319,7 +319,7 @@ private void addAdditionalDataFromJsonElementToJson (final Object item, final Js
319319

320320
/**
321321
* Add each non-transient additional data property to the given JSON node
322-
*
322+
*
323323
* @param additionalDataManager the additional data bag to iterate through
324324
* @param jsonNode the JSON node to add the additional data properties to
325325
*/
@@ -330,13 +330,13 @@ private void addAdditionalDataFromManagerToJson(AdditionalDataManager additional
330330
}
331331
}
332332
}
333-
333+
334334
private final static String ODATA_TYPE_KEY = "@odata.type";
335335
/**
336336
* Get the derived class for the given JSON object
337337
* This covers scenarios in which the service may return one of several derived types
338338
* of a base object, which it defines using the odata.type parameter
339-
*
339+
*
340340
* @param jsonObject the raw JSON object of the response
341341
* @param parentClass the parent class the derived class should inherit from
342342
* @return the derived class if found, or null if not applicable
@@ -348,9 +348,9 @@ public Class<?> getDerivedClass(@Nonnull final JsonObject jsonObject, @Nonnull f
348348
/** #microsoft.graph.user or #microsoft.graph.callrecords.callrecord */
349349
final String odataType = jsonObject.get(ODATA_TYPE_KEY).getAsString();
350350
final Integer lastDotIndex = odataType.lastIndexOf(".");
351-
final String derivedType = (odataType.substring(0, lastDotIndex) +
352-
".models.extensions." +
353-
CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL,
351+
final String derivedType = (odataType.substring(0, lastDotIndex) +
352+
".models." +
353+
CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL,
354354
odataType.substring(lastDotIndex + 1)))
355355
.replace("#", "com.");
356356
try {
@@ -373,7 +373,7 @@ public Class<?> getDerivedClass(@Nonnull final JsonObject jsonObject, @Nonnull f
373373

374374
/**
375375
* Gets the logger in use
376-
*
376+
*
377377
* @return a logger
378378
*/
379379
@VisibleForTesting

0 commit comments

Comments
 (0)