Skip to content

Commit 1930509

Browse files
authored
Merge pull request #122 from microsoftgraph/bugfix/json-memory-dedupe
- removes reference to serializer and json in IJsonBackedObject interface to reduce memory footprint
2 parents 8f807b4 + 5bf2db9 commit 1930509

11 files changed

Lines changed: 43 additions & 174 deletions

‎src/main/java/com/microsoft/graph/http/BaseCollectionPage.java‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ public class BaseCollectionPage<T, T2 extends BaseRequestBuilder<T>> implements
5353
*/
5454
private final T2 requestBuilder;
5555

56-
/**
57-
* The raw representation of this class
58-
*/
59-
private JsonObject rawObject;
60-
61-
/**
62-
* The serializer
63-
*/
64-
private ISerializer serializer;
65-
6656
/**
6757
* A collection page for WorkforceIntegration
6858
*
@@ -118,36 +108,13 @@ public List<T> getCurrentPage() {
118108
return pageContents;
119109
}
120110

121-
/**
122-
* Gets the raw representation of this class
123-
*
124-
* @return the raw representation of this class
125-
*/
126-
@Nullable
127-
public JsonObject getRawObject() {
128-
return rawObject;
129-
}
130-
131-
/**
132-
* Gets the serializer
133-
*
134-
* @return the serializer
135-
*/
136-
@Override
137-
@Nullable
138-
public ISerializer getSerializer() {
139-
return serializer;
140-
}
141-
142111
/**
143112
* Sets the raw JSON object
144113
*
145114
* @param serializer the serializer
146115
* @param json the JSON object to set this object to
147116
*/
148117
public void setRawObject(@Nonnull final ISerializer serializer, @Nonnull final JsonObject json) {
149-
this.serializer = serializer;
150-
rawObject = json;
151118
}
152119

153120
@Override

‎src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ public T3 buildFromResponse(@Nonnull final T2 response) {
130130
.getConstructor(String.class, IBaseClient.class, java.util.List.class)
131131
.newInstance(response.nextLink(), getBaseRequest().getClient(), options);
132132
final T3 page = (T3)this.collectionPageClass.getConstructor(response.getClass(), builder.getClass()).newInstance(response, response.nextLink() == null ? null : builder);
133-
page.setRawObject(response.getSerializer(), response.getRawObject());
134133
return page;
135134
} catch(IllegalArgumentException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException ex) {
136135
return null;

‎src/main/java/com/microsoft/graph/http/BaseCollectionResponse.java‎

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@
1111
import com.microsoft.graph.serializer.IJsonBackedObject;
1212
import com.microsoft.graph.serializer.ISerializer;
1313
import com.microsoft.graph.serializer.AdditionalDataManager;
14-
import com.microsoft.graph.http.ICollectionResponse;
1514

1615
/**
1716
* The basic collection response implementation
18-
*
17+
*
1918
* @param <T> the entity or complex type
2019
*/
21-
public abstract class BaseCollectionResponse<T> implements ICollectionResponse<T>, IJsonBackedObject {
22-
20+
public abstract class BaseCollectionResponse<T> implements ICollectionResponse<T> {
21+
2322
/**
2423
* The list of items within this collection page
2524
*/
2625
@SerializedName("value")
2726
@Expose
2827
@Nullable
2928
public java.util.List<T> value;
30-
29+
3130

3231
/**
3332
* The list of items within this collection page
@@ -43,7 +42,7 @@ public java.util.List<T> values() {
4342
@Expose(serialize = false)
4443
@Nullable
4544
public String nextLink;
46-
45+
4746
@Override
4847
@Nullable
4948
public String nextLink() {
@@ -58,48 +57,13 @@ public final AdditionalDataManager additionalDataManager() {
5857
return additionalDataManager;
5958
}
6059

61-
/**
62-
* The raw representation of this class
63-
*/
64-
@Nullable
65-
protected JsonObject rawObject;
66-
67-
/**
68-
* The serializer
69-
*/
70-
@Nullable
71-
protected ISerializer serializer;
72-
73-
/**
74-
* Gets the raw representation of this class
75-
*
76-
* @return the raw representation of this class
77-
*/
78-
@Nullable
79-
public JsonObject getRawObject() {
80-
return rawObject;
81-
}
82-
83-
/**
84-
* Gets serializer
85-
*
86-
* @return the serializer
87-
*/
88-
@Override
89-
@Nullable
90-
public ISerializer getSerializer() {
91-
return serializer;
92-
}
93-
9460
/**
9561
* Sets the raw JSON object
9662
*
9763
* @param serializer the serializer
9864
* @param json the JSON object to set this object to
9965
*/
10066
public void setRawObject(@Nonnull final ISerializer serializer, @Nonnull final JsonObject json) {
101-
this.serializer = serializer;
102-
rawObject = json;
10367
if (json.has("value")) {
10468
final JsonArray array = json.getAsJsonArray("value");
10569
for (int i = 0; i < array.size(); i++) {
@@ -110,4 +74,4 @@ public void setRawObject(@Nonnull final ISerializer serializer, @Nonnull final J
11074
}
11175
}
11276
}
113-
}
77+
}

‎src/main/java/com/microsoft/graph/http/DeltaCollectionPage.java‎

Lines changed: 8 additions & 10 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
@@ -22,11 +22,8 @@
2222

2323
package com.microsoft.graph.http;
2424

25-
import com.google.gson.JsonObject;
26-
import com.microsoft.graph.serializer.AdditionalDataManager;
27-
import com.microsoft.graph.serializer.ISerializer;
25+
import com.google.gson.JsonElement;
2826

29-
import java.util.Collections;
3027
import java.util.List;
3128

3229
import javax.annotation.Nullable;
@@ -39,7 +36,7 @@
3936
*/
4037
public class DeltaCollectionPage<T, T2 extends BaseRequestBuilder<T>> extends BaseCollectionPage<T, T2> {
4138
/**
42-
* The opaque link to query delta after the
39+
* The opaque link to query delta after the
4340
* initial request
4441
*/
4542
@Nullable
@@ -53,8 +50,9 @@ public class DeltaCollectionPage<T, T2 extends BaseRequestBuilder<T>> extends Ba
5350
*/
5451
public DeltaCollectionPage(@Nonnull final ICollectionResponse<T> response, @Nullable final T2 builder) {
5552
super(response.values(), builder, response.additionalDataManager());
56-
if (response.getRawObject().get("@odata.deltaLink") != null) {
57-
deltaLink = response.getRawObject().get("@odata.deltaLink").getAsString();
53+
final JsonElement deltaLinkRaw = response.additionalDataManager().get("@odata.deltaLink");
54+
if (deltaLinkRaw != null) {
55+
deltaLink = deltaLinkRaw.getAsString();
5856
} else {
5957
deltaLink = null;
6058
}

‎src/main/java/com/microsoft/graph/http/GraphErrorResponse.java‎

Lines changed: 3 additions & 21 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
@@ -66,22 +66,4 @@ public void setRawObject(@Nullable final ISerializer serializer, @Nonnull final
6666
public final AdditionalDataManager additionalDataManager() {
6767
return additionalDataManager;
6868
}
69-
70-
@Override
71-
@Nullable
72-
public ISerializer getSerializer() {
73-
return null;
74-
}
75-
76-
/**
77-
* Gets the raw JSON object for this object as parsed from
78-
* @return the JSON that this object was derived from
79-
*/
80-
@Override
81-
@Nullable
82-
public JsonObject getRawObject() {
83-
return rawObject;
84-
}
8569
}
86-
87-

‎src/main/java/com/microsoft/graph/http/ICollectionResponse.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
import javax.annotation.Nullable;
66

77
import com.microsoft.graph.serializer.IJsonBackedObject;
8-
import com.microsoft.graph.serializer.ISerializer;
98

109
/**
1110
* Represents a response of a collection of items returned by the service
1211
* @param <T> the type for the items in the response.
1312
*/
1413
public interface ICollectionResponse<T> extends IJsonBackedObject{
15-
/**
14+
/**
1615
* Gets the deserialized values the response contains
1716
* @return the deserialized values for the response
1817
*/

‎src/main/java/com/microsoft/graph/http/ReferenceRequestBody.java‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ public class ReferenceRequestBody implements IJsonBackedObject {
4444
@Nonnull
4545
public String odataId;
4646

47-
/**
48-
* The raw representation of this class
49-
*/
50-
private JsonObject rawObject;
51-
52-
/**
53-
* The serializer
54-
*/
55-
private ISerializer serializer;
56-
5747
/**
5848
* Instanciates a new reference request body from the serialized payload
5949
* @param payload payload to instanciate the body from
@@ -62,36 +52,13 @@ public ReferenceRequestBody(@Nonnull final String payload) {
6252
odataId = payload;
6353
}
6454

65-
/**
66-
* Gets the raw representation of this class
67-
*
68-
* @return the raw representation of this class
69-
*/
70-
@Nullable
71-
public JsonObject getRawObject() {
72-
return rawObject;
73-
}
74-
75-
/**
76-
* Gets serializer
77-
*
78-
* @return the serializer
79-
*/
80-
@Nullable
81-
@Override
82-
public ISerializer getSerializer() {
83-
return serializer;
84-
}
85-
8655
/**
8756
* Sets the raw JSON object
8857
*
8958
* @param serializer the serializer
9059
* @param json the JSON object to set this object to
9160
*/
9261
public void setRawObject(@Nonnull final ISerializer serializer, @Nonnull final JsonObject json) {
93-
this.serializer = serializer;
94-
this.rawObject = json;
9562
}
9663

9764
@Override

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

Lines changed: 5 additions & 21 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
@@ -41,27 +41,11 @@ public interface IJsonBackedObject {
4141
void setRawObject(@Nonnull final ISerializer serializer, @Nonnull final JsonObject json);
4242

4343
/**
44-
* Provides access to objects not anticipated in the model, as well as
44+
* Provides access to objects not anticipated in the model, as well as
4545
* request and response data from the HTTP call
46-
*
46+
*
4747
* @return the AddtionalDataManager
4848
*/
4949
@Nullable
5050
AdditionalDataManager additionalDataManager();
51-
52-
53-
/**
54-
* Gets the raw JSON object for this object as parsed from
55-
* @return the JSON that this object was derived from
56-
*/
57-
@Nullable
58-
JsonObject getRawObject();
59-
60-
/**
61-
* Gets serializer
62-
*
63-
* @return the serializer
64-
*/
65-
@Nullable
66-
ISerializer getSerializer();
6751
}

‎src/test/java/com/microsoft/graph/http/BaseCollectionPageTests.java‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import static org.junit.Assert.assertEquals;
66
import static org.junit.Assert.assertNotNull;
7-
import static org.junit.Assert.assertNull;
87
import static org.junit.Assert.assertTrue;
98

109
import java.util.ArrayList;
@@ -64,13 +63,7 @@ public void testNextPage() {
6463
public void testRawObject() {
6564
ISerializer serializer = mock(ISerializer.class);
6665
JsonObject jsonObject = new JsonObject();
67-
assertNull(baseCollectionPage.getRawObject());
68-
assertNull(baseCollectionPage.getSerializer());
6966
baseCollectionPage.setRawObject(serializer,jsonObject);
70-
assertNotNull(baseCollectionPage.getRawObject());
71-
assertNotNull(baseCollectionPage.getSerializer());
72-
assertEquals(serializer, baseCollectionPage.getSerializer());
73-
assertEquals(jsonObject, baseCollectionPage.getRawObject());
7467
}
7568

7669
}

0 commit comments

Comments
 (0)