Skip to content

Commit

Permalink
Revert "Fixing use of recently deprecated classes JsonToBeanConverter…
Browse files Browse the repository at this point in the history
… and BeanToJsonConverter"

This reverts commit 0ae8e3c.
  • Loading branch information
barancev committed Oct 27, 2017
1 parent 658f56d commit d36f497
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 68 deletions.
4 changes: 2 additions & 2 deletions java/client/src/org/openqa/selenium/firefox/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.google.common.io.LineReader;

import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.JsonToBeanConverter;

import java.io.File;
import java.io.FileReader;
Expand Down Expand Up @@ -92,7 +92,7 @@ public Preferences(Reader defaults, Reader reader) {
private void readDefaultPreferences(Reader defaultsReader) {
try {
String rawJson = CharStreams.toString(defaultsReader);
Map<String, Object> map = new Json().toType(rawJson, Map.class);
Map<String, Object> map = new JsonToBeanConverter().convert(Map.class, rawJson);

Map<String, Object> frozen = (Map<String, Object>) map.get("frozen");
for (Map.Entry<String, Object> entry : frozen.entrySet()) {
Expand Down
5 changes: 0 additions & 5 deletions java/client/src/org/openqa/selenium/json/Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
Expand Down Expand Up @@ -58,10 +57,6 @@ public String toJson(Object toConvert) {
return toJson.convert(toConvert);
}

public JsonElement toJsonElement(Object toConvert) {
return toJson.convertObject(toConvert);
}

public <T> T toType(Object source, Class<T> typeOfT) {
return toBean.convert(typeOfT, source);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public Optional<Result> createSession(HttpClient client, InputStream newSessionB
// W3C spec properly. Oh well.
Map<?, ?> blob;
try {
blob = new Json().toType(response.getContentString(), Map.class);
blob = new JsonToBeanConverter().convert(Map.class, response.getContentString());
} catch (JsonException e) {
throw new WebDriverException(
"Unable to parse remote response: " + response.getContentString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import org.openqa.selenium.internal.FindsByName;
import org.openqa.selenium.internal.FindsByTagName;
import org.openqa.selenium.internal.FindsByXPath;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.logging.LocalLogs;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingHandler;
Expand Down Expand Up @@ -749,7 +748,7 @@ public Set<Cookie> getCookies() {
Set<Cookie> toReturn = new HashSet<>();

List<Map<String, Object>> cookies =
new Json().toType(returned, List.class);
new JsonToBeanConverter().convert(List.class, returned);
if (cookies == null) {
return toReturn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
import static java.net.HttpURLConnection.HTTP_OK;

import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonException;
import org.openqa.selenium.remote.BeanToJsonConverter;
import org.openqa.selenium.remote.ErrorCodes;
import org.openqa.selenium.remote.JsonToBeanConverter;
import org.openqa.selenium.remote.Response;
import org.openqa.selenium.remote.ResponseCodec;

Expand All @@ -43,7 +44,8 @@
*/
public abstract class AbstractHttpResponseCodec implements ResponseCodec<HttpResponse> {
private final ErrorCodes errorCodes = new ErrorCodes();
private final Json json = new Json();
private final BeanToJsonConverter beanToJsonConverter = new BeanToJsonConverter();
private final JsonToBeanConverter jsonToBeanConverter = new JsonToBeanConverter();

/**
* Encodes the given response as a HTTP response message. This method is guaranteed not to throw.
Expand All @@ -57,7 +59,7 @@ public HttpResponse encode(Supplier<HttpResponse> factory, Response response) {
? HTTP_OK
: HTTP_INTERNAL_ERROR;

byte[] data = json.toJson(getValueToEncode(response)).getBytes(UTF_8);
byte[] data = beanToJsonConverter.convert(getValueToEncode(response)).getBytes(UTF_8);

HttpResponse httpResponse = factory.get();
httpResponse.setStatus(status);
Expand All @@ -77,7 +79,7 @@ public Response decode(HttpResponse encodedResponse) {
String contentType = nullToEmpty(encodedResponse.getHeader(CONTENT_TYPE));
String content = encodedResponse.getContentString().trim();
try {
return reconstructValue(json.toType(content, Response.class));
return reconstructValue(jsonToBeanConverter.convert(Response.class, content));
} catch (JsonException e) {
if (contentType.startsWith("application/json")) {
throw new IllegalArgumentException(
Expand Down
7 changes: 4 additions & 3 deletions java/client/test/org/openqa/selenium/ProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.openqa.selenium.Proxy.ProxyType;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.BeanToJsonConverter;
import org.openqa.selenium.remote.JsonToBeanConverter;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -382,8 +383,8 @@ public void serialiazesAndDeserializesWithoutError() {

Capabilities caps = new ImmutableCapabilities(PROXY, proxy);

String rawJson = new Json().toJson(caps);
Capabilities converted = new Json().toType(rawJson, Capabilities.class);
String rawJson = new BeanToJsonConverter().convert(caps);
Capabilities converted = new JsonToBeanConverter().convert(Capabilities.class, rawJson);

Object returnedProxy = converted.getCapability(PROXY);
assertTrue(returnedProxy instanceof Proxy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import org.junit.runners.JUnit4;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.BeanToJsonConverter;
import org.openqa.selenium.remote.JsonToBeanConverter;

import java.util.Map;

Expand Down Expand Up @@ -92,9 +93,9 @@ public void shouldSurviveASerializationRoundTrip() {
.withInitialBrowserUrl("http://www.cheese.com")
.addCommandSwitches("--cake");

String json = new Json().toJson(options);
String json = new BeanToJsonConverter().convert(options);
System.out.println("json = " + json);
Capabilities capabilities = new Json().toType(json, Capabilities.class);
Capabilities capabilities = new JsonToBeanConverter().convert(Capabilities.class, json);

assertEquals(options, capabilities);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.openqa.selenium.WrappedWebElement;
import org.openqa.selenium.interactions.PointerInput.Kind;
import org.openqa.selenium.interactions.PointerInput.Origin;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.BeanToJsonConverter;
import org.openqa.selenium.remote.RemoteWebElement;

/**
Expand All @@ -53,7 +53,7 @@ public void encodesWrappedElementInMoveOrigin() {
Duration.ofMillis(100), Origin.fromElement(element), 0, 0);
Sequence sequence = new Sequence(move.getSource(), 0).addAction(move);

String rawJson = new Json().toJson(sequence);
String rawJson = new BeanToJsonConverter().convert(sequence);
ActionSequenceJson json = new Gson().fromJson(rawJson, ActionSequenceJson.class);

assertEquals(json.actions.size(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.interactions.InvalidCoordinatesException;
import org.openqa.selenium.interactions.MoveTargetOutOfBoundsException;
import org.openqa.selenium.json.Json;

import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -521,7 +520,7 @@ private static void assertStackTracesEqual(StackTraceElement[] expected,

@SuppressWarnings({"unchecked"})
private static Map<String, Object> toMap(Object o) throws Exception {
String rawJson = new Json().toJson(o);
return new Json().toType(rawJson, Map.class);
String rawJson = new BeanToJsonConverter().convert(o);
return new JsonToBeanConverter().convert(Map.class, rawJson);
}
}
3 changes: 1 addition & 2 deletions java/client/test/org/openqa/selenium/remote/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.internal.HttpClientFactory;

import java.io.IOException;
Expand Down Expand Up @@ -96,7 +95,7 @@ public HttpUriRequest prepare(String url, Object payload) {
post.addHeader("Content-Type", "application/json; charset=utf8");

if (payload != null) {
String content = new Json().toJson(payload);
String content = new BeanToJsonConverter().convert(payload);
post.setEntity(new StringEntity(content, "UTF-8"));
}
return post;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.json.Json;

import java.net.MalformedURLException;
import java.util.Map;
Expand Down Expand Up @@ -109,7 +108,7 @@ public void shouldProperlyPopulateAnError() {
WebDriverException exception = new SessionNotCreatedException("me no likey");

ImmutableMap<String, ?> payload = ImmutableMap.of(
"value", new Gson().fromJson(new Json().toJson(exception), Map.class),
"value", new Gson().fromJson(new BeanToJsonConverter().convert(exception), Map.class),
"status", ErrorCodes.SESSION_NOT_CREATED);

InitialHandshakeResponse initialResponse = new InitialHandshakeResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
import org.junit.runners.JUnit4;
import org.openqa.selenium.ScriptTimeoutException;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.BeanToJsonConverter;
import org.openqa.selenium.remote.Dialect;
import org.openqa.selenium.remote.ErrorCodes;
import org.openqa.selenium.remote.JsonToBeanConverter;
import org.openqa.selenium.remote.RemoteWebElement;
import org.openqa.selenium.remote.Response;

Expand All @@ -60,7 +61,8 @@ public void convertsResponses_success() {
assertThat(converted.getStatus(), is(HTTP_OK));
assertThat(converted.getHeader(CONTENT_TYPE), is(JSON_UTF_8.toString()));

Response rebuilt = new Json().toType(new String(converted.getContent(), UTF_8), Response.class);
Response rebuilt = new JsonToBeanConverter().convert(
Response.class, new String(converted.getContent(), UTF_8));

assertEquals(response.getStatus(), rebuilt.getStatus());
assertEquals(new ErrorCodes().toState(response.getStatus()), rebuilt.getState());
Expand All @@ -78,7 +80,8 @@ public void convertsResponses_failure() {
assertThat(converted.getStatus(), is(HTTP_INTERNAL_ERROR));
assertThat(converted.getHeader(CONTENT_TYPE), is(JSON_UTF_8.toString()));

Response rebuilt = new Json().toType(new String(converted.getContent(), UTF_8), Response.class);
Response rebuilt = new JsonToBeanConverter().convert(
Response.class, new String(converted.getContent(), UTF_8));

assertEquals(response.getStatus(), rebuilt.getStatus());
assertEquals(new ErrorCodes().toState(response.getStatus()), rebuilt.getState());
Expand Down Expand Up @@ -151,7 +154,8 @@ public void decodeJsonResponseMissingContentType() {

HttpResponse httpResponse = new HttpResponse();
httpResponse.setStatus(HTTP_OK);
httpResponse.setContent(new Json().toJson(response).getBytes(UTF_8));
httpResponse.setContent(
new BeanToJsonConverter().convert(response).getBytes(UTF_8));

Response decoded = codec.decode(httpResponse);
assertEquals(response.getStatus(), decoded.getStatus());
Expand Down Expand Up @@ -185,7 +189,7 @@ public void decodeJsonResponseWithTrailingNullBytes() {
public void shouldConvertElementReferenceToRemoteWebElement() {
HttpResponse response = new HttpResponse();
response.setStatus(HTTP_OK);
response.setContent(new Json().toJson(ImmutableMap.of(
response.setContent(new BeanToJsonConverter().convert(ImmutableMap.of(
"status", 0,
"value", ImmutableMap.of(Dialect.OSS.getEncodedElementKey(), "345678"))).getBytes(UTF_8));

Expand All @@ -202,7 +206,8 @@ public void shouldAttemptToConvertAnExceptionIntoAnActualExceptionInstance() {

HttpResponse httpResponse = new HttpResponse();
httpResponse.setStatus(HTTP_CLIENT_TIMEOUT);
httpResponse.setContent(new Json().toJson(response).getBytes(UTF_8));
httpResponse.setContent(
new BeanToJsonConverter().convert(response).getBytes(UTF_8));

Response decoded = codec.decode(httpResponse);
assertEquals(ErrorCodes.ASYNC_SCRIPT_TIMEOUT, decoded.getStatus().intValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.JsonToBeanConverter;
import org.openqa.selenium.remote.LocalFileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.HttpClient;
Expand Down Expand Up @@ -83,7 +83,7 @@ private synchronized void startServers() {

// Keep polling the status page of the hub until it claims to be ready
HttpClient client = new ApacheHttpClient.Factory().createClient(hub.getWebDriverUrl());
Json json = new Json();
JsonToBeanConverter toBean = new JsonToBeanConverter();
Wait<HttpClient> wait = new FluentWait<>(client)
.ignoring(RuntimeException.class)
.withTimeout(30, TimeUnit.SECONDS);
Expand All @@ -95,7 +95,7 @@ private synchronized void startServers() {
} catch (IOException e) {
throw new RuntimeException(e);
}
Map<?, ?> value = json.toType(response.getContentString(), Map.class);
Map<?, ?> value = toBean.convert(Map.class, response.getContentString());

return ((Map<?, ?>) value.get("value")).get("ready") == Boolean.TRUE;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
import org.openqa.grid.internal.utils.configuration.converters.NoOpParameterSplitter;
import org.openqa.grid.internal.utils.configuration.validators.FileExistsValueValidator;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.BeanToJsonConverter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.JsonToBeanConverter;

import java.lang.reflect.Type;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -474,9 +475,9 @@ public JsonElement serialize(List<MutableCapabilities> desiredCapabilities, Type
JsonSerializationContext jsonSerializationContext) {

JsonArray capabilities = new JsonArray();
Json json = new Json();
BeanToJsonConverter converter = new BeanToJsonConverter();
for (MutableCapabilities dc : desiredCapabilities) {
capabilities.add(json.toJson(dc));
capabilities.add(converter.convertObject(dc));
}
return capabilities;
}
Expand All @@ -492,9 +493,9 @@ public List<MutableCapabilities> deserialize(JsonElement jsonElement, Type type,

if (jsonElement.isJsonArray()) {
List<MutableCapabilities> desiredCapabilities = new ArrayList<>();
Json json = new Json();
JsonToBeanConverter converter = new JsonToBeanConverter();
for (JsonElement arrayElement : jsonElement.getAsJsonArray()) {
desiredCapabilities.add(json.toType(arrayElement, DesiredCapabilities.class));
desiredCapabilities.add(converter.convert(DesiredCapabilities.class, arrayElement));
}
return desiredCapabilities;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.openqa.grid.internal.Registry;
import org.openqa.grid.internal.RemoteProxy;
import org.openqa.selenium.internal.BuildInfo;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.BeanToJsonConverter;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -86,7 +86,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
"value", value.build());

// Write out a minimal W3C status response.
byte[] payload = new Json().toJson(payloadObj).getBytes(UTF_8);
byte[] payload = new BeanToJsonConverter().convert(payloadObj).getBytes(UTF_8);

resp.setStatus(HTTP_OK);
resp.setHeader("Content-Type", JSON_UTF_8.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.internal.BuildInfo;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.BeanToJsonConverter;

import java.io.IOException;
import java.util.Map;
Expand Down Expand Up @@ -67,7 +67,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
"value", value.build());

// Write out a minimal W3C status response.
byte[] payload = new Json().toJson(payloadObj).getBytes(UTF_8);
byte[] payload = new BeanToJsonConverter().convert(payloadObj).getBytes(UTF_8);

resp.setStatus(HTTP_OK);
resp.setHeader("Content-Type", JSON_UTF_8.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
import org.openqa.grid.internal.Registry;
import org.openqa.grid.internal.RemoteProxy;
import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.JsonToBeanConverter;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -174,7 +175,8 @@ private void considerV2Json(GridNodeConfiguration configuration, JsonObject json
configuration.capabilities.clear();
JsonArray capabilities = json.get("capabilities").getAsJsonArray();
for (int i = 0; i < capabilities.size(); i++) {
MutableCapabilities cap = new Json().toType(capabilities.get(i), DesiredCapabilities.class);
MutableCapabilities cap = new JsonToBeanConverter()
.convert(DesiredCapabilities.class, capabilities.get(i));
configuration.capabilities.add(cap);
}
}
Expand Down
Loading

0 comments on commit d36f497

Please sign in to comment.