diff --git a/java/client/src/org/openqa/selenium/json/BeanToJsonConverter.java b/java/client/src/org/openqa/selenium/json/BeanToJsonConverter.java index 091cbeaad4018..9be3c2f691a76 100644 --- a/java/client/src/org/openqa/selenium/json/BeanToJsonConverter.java +++ b/java/client/src/org/openqa/selenium/json/BeanToJsonConverter.java @@ -245,8 +245,9 @@ private JsonElement mapObject(Object toConvert, int maxDepth, boolean skipNulls) continue; } + // Only include methods not on java.lang.Object to stop things being super-noisy Method readMethod = pd.getReadMethod(); - if (readMethod == null) { + if (readMethod == null || Object.class.equals(readMethod.getDeclaringClass())) { continue; } diff --git a/java/client/test/org/openqa/selenium/json/BeanToJsonConverterTest.java b/java/client/test/org/openqa/selenium/json/BeanToJsonConverterTest.java index 7ca667001be80..e0e02e4aa4cb4 100644 --- a/java/client/test/org/openqa/selenium/json/BeanToJsonConverterTest.java +++ b/java/client/test/org/openqa/selenium/json/BeanToJsonConverterTest.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.openqa.selenium.json.Json.MAP_TYPE; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedSet; @@ -59,6 +60,10 @@ import org.openqa.selenium.remote.SessionId; import java.awt.*; +import java.beans.FeatureDescriptor; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; @@ -70,6 +75,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.logging.Level; +import java.util.stream.Stream; @RunWith(JUnit4.class) @@ -534,6 +540,20 @@ public void shouldConvertAUrlToAString() throws MalformedURLException { assertEquals(url.toExternalForm(), converted.get("url").getAsString()); } + @Test + public void shouldNotIncludePropertiesFromJavaLangObjectOtherThanClass() + throws IntrospectionException { + String json = new BeanToJsonConverter().convert(new SimpleBean()); + + JsonObject converted = new JsonParser().parse(json).getAsJsonObject(); + + Stream.of(SimplePropertyDescriptor.getPropertyDescriptors(Object.class)) + .filter(pd -> !"class".equals(pd.getName())) + .map(SimplePropertyDescriptor::getName) + .peek(System.out::println) + .forEach(name -> assertFalse(name, converted.keySet().contains(name))); + } + @SuppressWarnings("unused") private static class SimpleBean {