You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thanks for contributing to Selenium! A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
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.
2, because the changes are localized to a single class and involve adding a straightforward serialization method. The logic is simple and the impact is limited to the serialization behavior of the Rectangle class.
🧪 Relevant tests
No
⚡ Possible issues
Missing Access Modifier: The toJson method should be declared as public if it is intended to be used outside the class. If it's for internal use, consider making it protected or package-private with a comment explaining its intended use.
Why: Adding null checks is a good practice to avoid NullPointerException, enhancing the robustness of the toJson method.
7
Best practice
Rename the toJson method to toMap for better clarity of its functionality
Rename the toJson method to toMap to better reflect its functionality of converting the object to a map representation, which can then be serialized to JSON.
Why: Renaming toJson to toMap could improve method naming clarity, reflecting that the method returns a map rather than a JSON string.
6
Enhancement
Change the visibility of the toJson method to public for better accessibility
Consider making the toJson method public to allow external classes to access the JSON representation of the Rectangle object. This will make the method more useful for serialization purposes.
Why: Making the toJson method public could enhance its utility for external use, but the necessity of this change depends on the design intent and potential security considerations.
5
Use HashMap instead of Map.of for creating the JSON representation to allow future modifications
Use a HashMap instead of Map.of to create the JSON representation. HashMap allows for more flexibility, such as modifying the map after creation if needed.
Why: While using HashMap provides flexibility, the suggestion lacks context on whether such flexibility is required, making it a potentially unnecessary change.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
The standard Rectangle class (
org.openqa.selenium.Rectangle
) lacks atoJson()
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
, andy
), the Rectangle class provides two methods that produce derived properties (dimension
andpoint
). Consequently, the JSON current returned for Rectangle objects includes these derived properties as well.Motivation and Context
Fixes #14035
Types of changes
Checklist
PR Type
Enhancement
Description
toJson
method to theRectangle
class to produce expected JSON serialization.toJson
method includes thewidth
,height
,x
, andy
properties in the JSON output.Map
class to facilitate JSON serialization.Changes walkthrough 📝
Rectangle.java
Add `toJson` method for JSON serialization in `Rectangle` class.
java/src/org/openqa/selenium/Rectangle.java
toJson
method to serializeRectangle
objects.width
,height
,x
, andy
properties in the JSON output.Map
class for JSON serialization.