Skip to content

Commit

Permalink
Fix the build by making json encode urls as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Jan 18, 2018
1 parent 21a6c7a commit 2590fda
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Expand Up @@ -34,6 +34,7 @@
import java.io.File;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
Expand Down Expand Up @@ -173,6 +174,10 @@ private JsonElement convertObject(Object toConvert, int maxDepth) throws Excepti
return new JsonPrimitive(((File) toConvert).getAbsolutePath());
}

if (toConvert instanceof URL) {
return new JsonPrimitive(((URL) toConvert).toExternalForm());
}

Method toJson = getMethod(toConvert, "toJson");
if (toJson != null) {
try {
Expand Down
1 change: 1 addition & 0 deletions java/client/src/org/openqa/selenium/json/Json.java
Expand Up @@ -46,6 +46,7 @@ public class Json {
.registerTypeAdapterFactory(MapAdapter.FACTORY)
.setLenient()
.serializeNulls()
.disableHtmlEscaping()
.create();

public static final Type LIST_OF_MAPS_TYPE = new TypeToken<List<Map<String, Object>>>() {}.getType();
Expand Down
Expand Up @@ -60,6 +60,8 @@

import java.awt.*;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -521,6 +523,17 @@ public void testShouldBeAbleToConvertACommand() {
assertEquals(pars.get("param2").getAsString(), parameters.get("param2"));
}

@Test
public void shouldConvertAUrlToAString() throws MalformedURLException {
URL url = new URL("http://example.com/cheese?type=edam");
ImmutableMap<String, URL> toConvert = ImmutableMap.of("url", url);

String seen = new Json().toJson(toConvert);
JsonObject converted = new JsonParser().parse(seen).getAsJsonObject();

assertEquals(url.toExternalForm(), converted.get("url").getAsString());
}

@SuppressWarnings("unused")
private static class SimpleBean {

Expand Down

0 comments on commit 2590fda

Please sign in to comment.