-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Closed
Labels
C-javaJava BindingsJava BindingsI-defectSomething is not working as intendedSomething is not working as intended
Description
What happened?
The standard Rectangle class (org.openqa.selenium.Rectangle) lacks a toJson() method, which causes the serialization performed by the Json API to fall back to scanning for methods that look like JavaBean accessors to extract object properties. In addition to the methods that provide access to inherent properties (width, height, x, and y), the Rectangle class provides two methods that produce derived properties (dimension and point). Consequently, the JSON current returned for Rectangle objects includes these derived properties as well.
How can we reproduce the issue?
@Test
public void serializeRectangle() {
Rectangle r = new Rectangle(640, 480, 320, 240);
String j = new Json().toJson(r);
System.out.println(j);
}
static class NewRectangle extends Rectangle {
public NewRectangle(int x, int y, int height, int width) {
super(x, y, height, width);
}
private Map<String, Object> toJson() {
return Map.of("width", width, "height", height, "x", x, "y", y);
}
}
@Test
public void serializeNewRectangle() {
Rectangle r = new NewRectangle(640, 480, 320, 240);
String j = new Json().toJson(r);
System.out.println(j);
}Relevant log output
// output from `serializeRectangle`
{
"width": 240,
"x": 640,
"y": 480,
"class": "org.openqa.selenium.Rectangle",
"dimension": {
"width": 240,
"class": "org.openqa.selenium.Dimension",
"height": 320
},
"point": {
"x": 640,
"y": 480,
"class": "org.openqa.selenium.Point"
},
"height": 320
}
// output from `serializeNewRectangle`
{
"x": 640,
"y": 480,
"width": 240,
"height": 320
}
### Operating System
Irrelevant
### Selenium version
Java 4.21.0
### What are the browser(s) and version(s) where you see this issue?
None
### What are the browser driver(s) and version(s) where you see this issue?
None
### Are you using Selenium Grid?
Irrelevant
Metadata
Metadata
Assignees
Labels
C-javaJava BindingsJava BindingsI-defectSomething is not working as intendedSomething is not working as intended