Skip to content

Commit 2590fda

Browse files
committed
Fix the build by making json encode urls as strings
1 parent 21a6c7a commit 2590fda

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.io.File;
3535
import java.lang.reflect.Array;
3636
import java.lang.reflect.Method;
37+
import java.net.URL;
3738
import java.util.Collection;
3839
import java.util.Date;
3940
import java.util.Map;
@@ -173,6 +174,10 @@ private JsonElement convertObject(Object toConvert, int maxDepth) throws Excepti
173174
return new JsonPrimitive(((File) toConvert).getAbsolutePath());
174175
}
175176

177+
if (toConvert instanceof URL) {
178+
return new JsonPrimitive(((URL) toConvert).toExternalForm());
179+
}
180+
176181
Method toJson = getMethod(toConvert, "toJson");
177182
if (toJson != null) {
178183
try {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class Json {
4646
.registerTypeAdapterFactory(MapAdapter.FACTORY)
4747
.setLenient()
4848
.serializeNulls()
49+
.disableHtmlEscaping()
4950
.create();
5051

5152
public static final Type LIST_OF_MAPS_TYPE = new TypeToken<List<Map<String, Object>>>() {}.getType();

java/client/test/org/openqa/selenium/json/BeanToJsonConverterTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060

6161
import java.awt.*;
6262
import java.io.StringReader;
63+
import java.net.MalformedURLException;
64+
import java.net.URL;
6365
import java.util.Date;
6466
import java.util.HashMap;
6567
import java.util.HashSet;
@@ -521,6 +523,17 @@ public void testShouldBeAbleToConvertACommand() {
521523
assertEquals(pars.get("param2").getAsString(), parameters.get("param2"));
522524
}
523525

526+
@Test
527+
public void shouldConvertAUrlToAString() throws MalformedURLException {
528+
URL url = new URL("http://example.com/cheese?type=edam");
529+
ImmutableMap<String, URL> toConvert = ImmutableMap.of("url", url);
530+
531+
String seen = new Json().toJson(toConvert);
532+
JsonObject converted = new JsonParser().parse(seen).getAsJsonObject();
533+
534+
assertEquals(url.toExternalForm(), converted.get("url").getAsString());
535+
}
536+
524537
@SuppressWarnings("unused")
525538
private static class SimpleBean {
526539

0 commit comments

Comments
 (0)