Skip to content

Commit 2997a70

Browse files
committed
Moving from org.json to gson because the license. Fixes issue 7956
1 parent 463aff1 commit 2997a70

File tree

63 files changed

+1013
-1330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1013
-1330
lines changed

Diff for: .idea/libraries/simple_json.xml renamed to .idea/libraries/gson.xml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: java/client/client.iml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<orderEntry type="library" scope="RUNTIME" name="cssparser" level="project" />
2525
<orderEntry type="library" exported="" name="guava-libraries" level="project" />
2626
<orderEntry type="library" name="google-protobuffers" level="project" />
27+
<orderEntry type="library" exported="" name="gson" level="project" />
2728
<orderEntry type="library" name="hamcrest" level="project" />
2829
<orderEntry type="library" name="htmlunit" level="project" />
2930
<orderEntry type="library" name="jna" level="project" />
@@ -32,7 +33,6 @@
3233
<orderEntry type="library" exported="" name="operadriver" level="project" />
3334
<orderEntry type="library" name="phantomjsdriver" level="project" />
3435
<orderEntry type="library" name="servlet-api" level="project" />
35-
<orderEntry type="library" exported="" name="simple-json" level="project" />
3636
<orderEntry type="library" name="testng" level="project" />
3737
<orderEntry type="library" name="webbit" level="project" />
3838
<orderEntry type="library" name="xml-apis" level="project" />

Diff for: java/client/src/org/openqa/selenium/JavascriptExecutor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ public interface JavascriptExecutor {
122122
* " }" +
123123
* "};" +
124124
* "xhr.send();");
125-
* JSONObject json = new JSONObject((String) response);
126-
* assertEquals("cheese", json.getString("food"));
125+
* JsonObject json = new JsonParser().parse((String) response);
126+
* assertEquals("cheese", json.get("food").getAsString());
127127
* </pre></code>
128128
*
129129
* <p>

Diff for: java/client/src/org/openqa/selenium/chrome/BUCK

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ java_library(
1010
'//java/client/src/org/openqa/selenium/remote:remote',
1111
'//java/client/src/org/openqa/selenium/remote/service:service',
1212
'//third_party/java/guava-libraries:guava-libraries',
13-
'//third_party/java/json:json',
1413
],
1514
visibility = [ 'PUBLIC' ],
1615
)

Diff for: java/client/src/org/openqa/selenium/chrome/ChromeOptions.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import com.google.common.collect.Lists;
2626
import com.google.common.collect.Maps;
2727
import com.google.common.io.Files;
28+
import com.google.gson.Gson;
29+
import com.google.gson.JsonElement;
2830

29-
import org.json.JSONException;
30-
import org.json.JSONObject;
3131
import org.openqa.selenium.internal.Base64Encoder;
3232
import org.openqa.selenium.remote.DesiredCapabilities;
3333

@@ -198,13 +198,10 @@ public Object getExperimentalOption(String name) {
198198
* @return The JSON representation of these options.
199199
* @throws IOException If an error occurs while reading the
200200
* {@link #addExtensions(java.util.List) extension files} from disk.
201-
* @throws JSONException If an error occurs while encoding these options as
202-
* JSON.
203201
*/
204-
public JSONObject toJson() throws IOException, JSONException {
205-
JSONObject options = new JSONObject();
206-
// copy experimental options, instead of passing to the JSONObject constructor
207-
// because the JSON library will mutate the map passed in.
202+
public JsonElement toJson() throws IOException {
203+
Map<String, Object> options = Maps.newHashMap();
204+
208205
for (String key : experimentalOptions.keySet()) {
209206
options.put(key, experimentalOptions.get(key));
210207
}
@@ -224,7 +221,7 @@ public JSONObject toJson() throws IOException, JSONException {
224221
encoded_extensions.addAll(extensions);
225222
options.put("extensions", encoded_extensions);
226223

227-
return options;
224+
return new Gson().toJsonTree(options);
228225
}
229226

230227
/**

Diff for: java/client/src/org/openqa/selenium/chrome/build.desc

-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ java_library(name = "chrome",
88
"//java/client/src/org/openqa/selenium/remote",
99
"//java/client/src/org/openqa/selenium/remote/service",
1010
"//third_party/java/guava-libraries",
11-
"//third_party/java/json",
1211
])

Diff for: java/client/src/org/openqa/selenium/firefox/Preferences.java

+9-18
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424
import com.google.common.io.CharStreams;
2525
import com.google.common.io.LineReader;
2626

27-
import org.json.JSONException;
28-
import org.json.JSONObject;
2927
import org.openqa.selenium.WebDriverException;
3028
import org.openqa.selenium.io.IOUtils;
31-
import org.openqa.selenium.remote.JsonException;
29+
import org.openqa.selenium.remote.JsonToBeanConverter;
3230

3331
import java.io.File;
3432
import java.io.FileReader;
3533
import java.io.IOException;
3634
import java.io.Reader;
3735
import java.io.Writer;
38-
import java.util.Iterator;
3936
import java.util.Map;
4037
import java.util.regex.Matcher;
4138
import java.util.regex.Pattern;
@@ -95,26 +92,20 @@ public Preferences(Reader defaults, Reader reader) {
9592
private void readDefaultPreferences(Reader defaultsReader) {
9693
try {
9794
String rawJson = CharStreams.toString(defaultsReader);
98-
JSONObject jsonPrefs = new JSONObject(rawJson);
95+
Map<String, Object> map = new JsonToBeanConverter().convert(Map.class, rawJson);
9996

100-
JSONObject frozen = jsonPrefs.getJSONObject("frozen");
101-
Iterator keys = frozen.keys();
102-
while (keys.hasNext()) {
103-
String key = (String) keys.next();
104-
Object value = frozen.get(key);
97+
Map<String, Object> frozen = (Map<String, Object>) map.get("frozen");
98+
for (Map.Entry<String, Object> entry : frozen.entrySet()) {
99+
String key = entry.getKey();
100+
Object value = entry.getValue();
105101
setPreference(key, value);
106102
immutablePrefs.put(key, value);
107103
}
108104

109-
JSONObject mutable = jsonPrefs.getJSONObject("mutable");
110-
keys = mutable.keys();
111-
while (keys.hasNext()) {
112-
String key = (String) keys.next();
113-
Object value = mutable.get(key);
114-
setPreference(key, value);
105+
Map<String, Object> mutable = (Map<String, Object>) map.get("mutable");
106+
for (Map.Entry<String, Object> entry : mutable.entrySet()) {
107+
setPreference(entry.getKey(), entry.getValue());
115108
}
116-
} catch (JSONException e) {
117-
throw new JsonException(e);
118109
} catch (IOException e) {
119110
throw new WebDriverException(e);
120111
}

Diff for: java/client/src/org/openqa/selenium/logging/BUCK

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ java_library(name = 'logging',
1919
':api',
2020
'//java/client/src/org/openqa/selenium:beta',
2121
'//third_party/java/guava-libraries:guava-libraries',
22-
'//third_party/java/json:json',
22+
'//third_party/java/gson:gson',
2323
],
2424
visibility = ['PUBLIC'],
2525
)

Diff for: java/client/src/org/openqa/selenium/logging/SessionLogHandler.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717

1818
package org.openqa.selenium.logging;
1919

20-
import org.json.JSONException;
21-
import org.json.JSONObject;
20+
import com.google.gson.JsonElement;
21+
import com.google.gson.JsonObject;
2222

2323
import java.util.HashMap;
24-
import java.util.Iterator;
2524
import java.util.Map;
2625

2726
public class SessionLogHandler {
@@ -32,16 +31,14 @@ public class SessionLogHandler {
3231
*
3332
* @param rawSessionMap The raw session map.
3433
* @return The session logs mapped to session IDs.
35-
* @throws Exception If something goes wrong in server communication or JSON parsing.
3634
*/
37-
public static Map<String, SessionLogs> getSessionLogs(JSONObject rawSessionMap)
38-
throws JSONException {
35+
public static Map<String, SessionLogs> getSessionLogs(JsonObject rawSessionMap) {
3936
Map<String, SessionLogs> sessionLogsMap = new HashMap<String, SessionLogs>();
40-
for (Iterator keyItr = rawSessionMap.keys(); keyItr.hasNext();) {
41-
String sessionId = (String) keyItr.next();
42-
SessionLogs sessionLogs = SessionLogs.fromJSON(rawSessionMap.getJSONObject(sessionId));
37+
for (Map.Entry<String, JsonElement> entry : rawSessionMap.entrySet()) {
38+
String sessionId = entry.getKey();
39+
SessionLogs sessionLogs = SessionLogs.fromJSON(entry.getValue().getAsJsonObject());
4340
sessionLogsMap.put(sessionId, sessionLogs);
4441
}
45-
return sessionLogsMap;
42+
return sessionLogsMap;
4643
}
4744
}

Diff for: java/client/src/org/openqa/selenium/logging/SessionLogs.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717

1818
package org.openqa.selenium.logging;
1919

20-
import org.json.JSONArray;
21-
import org.json.JSONException;
22-
import org.json.JSONObject;
20+
import com.google.gson.JsonArray;
21+
import com.google.gson.JsonElement;
22+
import com.google.gson.JsonObject;
2323

2424
import org.openqa.selenium.Beta;
2525

2626
import java.util.ArrayList;
2727
import java.util.Collections;
2828
import java.util.HashMap;
29-
import java.util.Iterator;
3029
import java.util.List;
3130
import java.util.Map;
3231
import java.util.Set;
@@ -61,17 +60,19 @@ public Map<String, LogEntries> getAll() {
6160
return Collections.unmodifiableMap(logTypeToEntriesMap);
6261
}
6362

64-
public static SessionLogs fromJSON(JSONObject rawSessionLogs) throws JSONException {
63+
public static SessionLogs fromJSON(JsonObject rawSessionLogs) {
6564
SessionLogs sessionLogs = new SessionLogs();
66-
for (Iterator logTypeItr = rawSessionLogs.keys(); logTypeItr.hasNext();) {
67-
String logType = (String) logTypeItr.next();
68-
JSONArray rawLogEntries = rawSessionLogs.getJSONArray(logType);
65+
for (Map.Entry<String, JsonElement> entry : rawSessionLogs.entrySet()) {
66+
String logType = entry.getKey();
67+
JsonArray rawLogEntries = entry.getValue().getAsJsonArray();
6968
List<LogEntry> logEntries = new ArrayList<LogEntry>();
70-
for (int index = 0; index < rawLogEntries.length(); index++) {
71-
JSONObject rawEntry = rawLogEntries.getJSONObject(index);
72-
logEntries.add(new LogEntry(LogLevelMapping.toLevel(rawEntry.getString("level")),
73-
rawEntry.getLong("timestamp"), rawEntry.getString("message")));
74-
}
69+
for (int index = 0; index < rawLogEntries.size(); index++) {
70+
JsonObject rawEntry = rawLogEntries.get(index).getAsJsonObject();
71+
logEntries.add(new LogEntry(LogLevelMapping.toLevel(
72+
rawEntry.get("level").getAsString()),
73+
rawEntry.get("timestamp").getAsLong(),
74+
rawEntry.get("message").getAsString()));
75+
}
7576
sessionLogs.addLog(logType, new LogEntries(logEntries));
7677
}
7778
return sessionLogs;

Diff for: java/client/src/org/openqa/selenium/logging/build.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ java_library(
3333
":api",
3434
"//java/client/src/org/openqa/selenium:base",
3535
"//third_party/java/guava-libraries",
36-
"//third_party/java/json",
36+
"//third_party/java/gson",
3737
])
3838

Diff for: java/client/src/org/openqa/selenium/logging/profiler/HttpProfilerLogEntry.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818

1919
import java.util.Map;
2020

21-
import org.json.JSONObject;
22-
2321
import com.google.common.collect.ImmutableMap;
22+
import com.google.gson.Gson;
2423

2524
public class HttpProfilerLogEntry extends ProfilerLogEntry {
2625

@@ -33,7 +32,7 @@ private static String constructMessage(EventType eventType, String commandName,
3332
"event", eventType.toString(),
3433
"command", commandName,
3534
"startorend", isStart ? "start" : "end");
36-
return new JSONObject(map).toString();
35+
return new Gson().toJson(map);
3736
}
3837

3938
}

Diff for: java/client/src/org/openqa/selenium/remote/BUCK

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ java_library(name = 'remote',
9191
'//java/client/src/org/openqa/selenium/net:net',
9292
'//third_party/java/apache-httpclient:apache-httpclient',
9393
'//third_party/java/guava-libraries:guava-libraries',
94-
'//third_party/java/json:json',
94+
'//third_party/java/gson:gson',
9595
],
9696
visibility = ['PUBLIC'],
9797
)

0 commit comments

Comments
 (0)