Skip to content

Commit 7a0e54a

Browse files
committed
Remove Json.toJsonElement
1 parent 60adb20 commit 7a0e54a

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

java/client/src/org/openqa/selenium/json/Json.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.common.reflect.TypeToken;
2222
import com.google.gson.Gson;
2323
import com.google.gson.GsonBuilder;
24-
import com.google.gson.JsonElement;
2524

2625
import java.io.IOException;
2726
import java.io.Reader;
@@ -32,7 +31,7 @@
3231
import java.util.Map;
3332

3433
public class Json {
35-
final static Gson GSON = new GsonBuilder()
34+
static final Gson GSON = new GsonBuilder()
3635
.setLenient()
3736
.serializeNulls()
3837
.disableHtmlEscaping()
@@ -49,14 +48,6 @@ public String toJson(Object toConvert) {
4948
return toJson.convert(toConvert);
5049
}
5150

52-
/**
53-
* @deprecated No replacement. Use raw java types instead.
54-
*/
55-
@Deprecated
56-
public JsonElement toJsonElement(Object toConvert) {
57-
return toJson.convertObject(toConvert);
58-
}
59-
6051
public <T> T toType(String source, Type typeOfT) {
6152
return toType(source, typeOfT, PropertySetting.BY_NAME);
6253
}

java/server/src/org/openqa/selenium/remote/server/rest/Responses.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717

1818
package org.openqa.selenium.remote.server.rest;
1919

20+
import static org.openqa.selenium.json.Json.MAP_TYPE;
21+
2022
import com.google.gson.JsonObject;
2123

2224
import org.openqa.selenium.json.Json;
2325
import org.openqa.selenium.remote.ErrorCodes;
2426
import org.openqa.selenium.remote.Response;
2527
import org.openqa.selenium.remote.SessionId;
2628

29+
import java.util.Map;
2730
import java.util.Optional;
2831

2932
/**
@@ -83,9 +86,11 @@ public static Response failure(
8386
response.setState(ERROR_CODES.toState(response.getStatus()));
8487

8588
if (reason != null) {
86-
JsonObject json = new Json().toJsonElement(reason).getAsJsonObject();
87-
screenshot.ifPresent(screen -> json.addProperty("screen", screen));
88-
response.setValue(json);
89+
Json json = new Json();
90+
String raw = json.toJson(reason);
91+
Map<String, Object> value = json.toType(raw, MAP_TYPE);
92+
screenshot.ifPresent(screen -> value.put("screen", screen));
93+
response.setValue(value);
8994
}
9095
return response;
9196
}

0 commit comments

Comments
 (0)