Skip to content

Commit 00944b6

Browse files
author
Caitlin Bales (MSFT)
authored
Merge pull request #11 from davidmoten/fix-deps
remove org.json:json, javax.ws.rs deps and upgrade gson dep to 2.8.2
2 parents ec2f771 + 1ed555b commit 00944b6

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

build.gradle

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@ dependencies {
2929
// Use JUnit test framework
3030
testImplementation 'junit:junit:4.12'
3131

32-
compile 'com.google.code.gson:gson:2.2.4'
33-
compile 'org.json:json:20141113'
34-
compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0-m02'
32+
compile 'com.google.code.gson:gson:2.8.2'
3533

36-
// https://mvnrepository.com/artifact/com.sun.jersey/jersey-server
37-
compile group: 'com.sun.jersey', name: 'jersey-server', version: '1.19.4'
34+
compile 'com.sun.jersey:jersey-server:1.19.4'
3835
}
3936

4037
publishing {

src/main/java/com/microsoft/graph/http/GraphServiceException.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,19 @@
2222

2323
package com.microsoft.graph.http;
2424

25-
import com.microsoft.graph.core.ClientException;
26-
import com.microsoft.graph.core.GraphErrorCodes;
27-
import com.microsoft.graph.options.HeaderOption;
28-
import com.microsoft.graph.serializer.ISerializer;
29-
30-
import org.json.JSONException;
31-
import org.json.JSONObject;
32-
3325
import java.io.IOException;
3426
import java.util.LinkedList;
3527
import java.util.List;
3628
import java.util.Locale;
3729
import java.util.Map;
3830

31+
import com.google.gson.Gson;
32+
import com.google.gson.GsonBuilder;
33+
import com.microsoft.graph.core.ClientException;
34+
import com.microsoft.graph.core.GraphErrorCodes;
35+
import com.microsoft.graph.options.HeaderOption;
36+
import com.microsoft.graph.serializer.ISerializer;
37+
3938
/**
4039
* An exception from the Graph service.
4140
*/
@@ -61,11 +60,6 @@ public class GraphServiceException extends ClientException {
6160
*/
6261
protected static final int MAX_BYTE_COUNT_BEFORE_TRUNCATION = 8;
6362

64-
/**
65-
* The intent spacing on JSON based responses.
66-
*/
67-
public static final int INDENT_SPACES = 3;
68-
6963
/**
7064
* The internal server error threshold defined by the HTTP protocol.
7165
*/
@@ -201,9 +195,9 @@ public String getMessage(final boolean verbose) {
201195
}
202196
if (verbose && error != null && error.rawObject != null) {
203197
try {
204-
final JSONObject jsonObject = new JSONObject(error.rawObject.toString());
205-
sb.append(jsonObject.toString(INDENT_SPACES)).append(NEW_LINE);
206-
} catch (final JSONException ignored) {
198+
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
199+
sb.append(gson.toJson(error.rawObject)).append(NEW_LINE);
200+
} catch (final RuntimeException ignored) {
207201
sb.append("[Warning: Unable to parse error message body]").append(NEW_LINE);
208202
}
209203
} else {

src/test/java/com/microsoft/graph/functional/TestBase.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.microsoft.graph.functional;
22

3+
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
5+
import com.google.gson.JsonObject;
36
import com.microsoft.graph.authentication.IAuthenticationProvider;
47
import com.microsoft.graph.core.DefaultClientConfig;
58
import com.microsoft.graph.core.IClientConfig;
@@ -8,8 +11,6 @@
811
import com.microsoft.graph.models.extensions.GraphServiceClient;
912
import com.microsoft.graph.core.Constants;
1013

11-
import org.json.JSONObject;
12-
1314
import java.io.BufferedReader;
1415
import java.io.InputStreamReader;
1516
import java.io.OutputStreamWriter;
@@ -96,7 +97,7 @@ private String GetAccessToken()
9697
}
9798
conn.disconnect();
9899

99-
JSONObject res = new JSONObject(jsonString.toString());
100+
JsonObject res = new GsonBuilder().create().fromJson(jsonString.toString(), JsonObject.class);
100101
return res.get("access_token").toString();
101102

102103
} catch (Exception e) {

0 commit comments

Comments
 (0)