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

The "similar" methods do not accurately compare JSONString objects #682

Closed
spaffrath opened this issue Aug 4, 2022 · 3 comments
Closed

Comments

@spaffrath
Copy link
Contributor

A JSON object or array that contains a value of type JSONString will never register as "similar" to another object or array that contains an equivalent JSONString. Given that JSONString has a single function that returns a string, and that the string representation of that json will always be the same, the similar method should evaluate them to true.

To demonstrate, these are couple of tests that can be dropped into the existing JUnit suite:

        JSONObject jo1 = new JSONObject()
                .put("a", new MyJsonString());
        JSONObject jo2 = new JSONObject()
                .put("a", new MyJsonString());
        assertTrue(jo1.toString().equals(jo2.toString())); // true
        assertTrue(jo1.similar(jo2)); // false

        JSONArray ja1 = new JSONArray()
                .put(new MyJsonString());
        JSONArray ja2 = new JSONArray()
                .put(new MyJsonString());
        assertTrue(ja1.toString().equals(ja2.toString())); // true
        assertTrue(ja1.similar(ja2)); // false
@spaffrath
Copy link
Contributor Author

This is a couple of lines in each similar method. If the change is agreed on, then I'll do a PR.

@stleary
Copy link
Owner

stleary commented Aug 5, 2022

@spaffrath Thanks, sounds like this might be a bug that should be fixed. OK to submit a PR.

@stleary
Copy link
Owner

stleary commented Aug 24, 2022

This issue is now being tracked by #683

@stleary stleary closed this as completed Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants