Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Selenium Java API: Serialization of 'Rectangle' objects by the Json API includes derived properties #14035

Closed
sbabcoc opened this issue May 24, 2024 · 2 comments · Fixed by #14038

Comments

@sbabcoc
Copy link
Contributor

sbabcoc commented May 24, 2024

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
Copy link

@sbabcoc, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

Copy link

This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants