Visitar URL original
The "similar" methods do not accurately compare JSONString objects · Issue #682 · stleary/JSON-java · GitHub
Skip to content

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

Closed

Description

@spaffrath

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

Activity

  1. spaffrath commented on Aug 4, 2022

    @spaffrath
    ContributorAuthor

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

  2. stleary commented on Aug 5, 2022

    @stleary
    Owner

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

  3. stleary commented on Aug 24, 2022

    @stleary
    Owner

    This issue is now being tracked by #683

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions