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

1.0 <> 1 #20

Open
boekhold opened this issue Aug 30, 2016 · 5 comments
Open

1.0 <> 1 #20

boekhold opened this issue Aug 30, 2016 · 5 comments

Comments

@boekhold
Copy link

If I compare the following 2 fragments:

expected:

{
    "value" : 1.0
}

test data:

{
    "value" : 1
}

zjsonpatch considers this different and generates a As far as I am aware, in JavaScript/JSON there is no distinction between integers and floats/doubles: they are all considered 'numbers'.

zjsonpatch should not generate a "replace" patch node for this.

@vishwakarma
Copy link
Member

Agreed,
Its data portability issue trickled down because of language implementation.

@vinesh2011
Copy link

any idea when can we get this fixed?

@boekhold
Copy link
Author

boekhold commented Dec 8, 2016

The problem is really in Jackson. If you have a Json document that has "field":"0", it is parsed internally as a java.lang.Integer. Similarly, "field":"0.0" is parsed as a Double. And JsonNode.equals() doesn't consider those to be the same, because it also compares the class.

In my case, the JSON I'm comparing is actually produced by org.json.JSONObject.toString(), which has the annoying habit of dropping the ".0" from "0.0", which (IMO) drops implicit type information for a value. If the original document author wrote "0.0", or the programmer used 'jsonObject.put("field", 0.0)', he clearly intended the field to represent a Double.

I actually just commented on an existing (closed) issue for org.json about this: stleary/JSON-java#134

@pankaj-s
Copy link

Jackson Coreutils might be helpful here as it provides numeric equivalence.

@grimsa
Copy link

grimsa commented Aug 24, 2020

Jackson Coreutils might be helpful here as it provides numeric equivalence.

Note: jackson-coreutils moved under java-json-tools group ID: https://github.com/java-json-tools/jackson-coreutils

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

5 participants