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

Issue with JSONObject::similar #616

Closed
mathijs81 opened this issue Jul 22, 2021 · 2 comments · Fixed by #617
Closed

Issue with JSONObject::similar #616

mathijs81 opened this issue Jul 22, 2021 · 2 comments · Fixed by #617

Comments

@mathijs81
Copy link

After upgrading from 20200518 to 20210307 some of our tests that are using JSONObject::similar started to fail.

This case reproduces the problem:

        JSONObject a = new JSONObject();
        a.put("a", 1.1);
        JSONObject b = new JSONObject("{\"a\":1.1}");
        System.out.println("a: " + a.toString(0));
        System.out.println("b: " + b.toString(0));
        System.out.println(a.similar(b));

This creates two JSONObjects whose value is just {"a":1.1}.

The output of this snippet on 20200518 is

a: {"a":1.1}
b: {"a":1.1}
true

but on version 20210307 the similar call suddenly returns false, even though the string representations of the objects are the same:

a: {"a":1.1}
b: {"a":1.1}
false
@stleary
Copy link
Owner

stleary commented Jul 22, 2021

@mathijs81 Thanks for bringing this up, will investigate and someone will get back to you soon.

@stleary
Copy link
Owner

stleary commented Jul 23, 2021

The 'a' value is set by put(double) and is not exactly equal to 1.1.
The 'b' value is initialized by parsing a string in the JSONObject constructor. Due to recent changes, it is parsed into a BigDecimal, and is exactly equal to 1.1.

I think this needs to be fixed. If anyone has preferences or opinions on how to fix it, please post here. Otherwise, I will come up with a solution in a few days.

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

Successfully merging a pull request may close this issue.

2 participants