Skip to content

JSONTokener recognizes -0 as a string not as a number, based on usage from json-schema #187

Closed

Description

@coderextreme

Activity

  1. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor

    I fixed this in #157 and #158 but it was not accepted.

  2. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor
  3. coderextreme commented on Jan 27, 2016

    @coderextreme
    Author

    This is breaking schema validation because strings (-0) aren't numbers. We might be able to change the JSON, but it seems odd that this is not acceptable to JSON-java. -0 is well-defined in the spec and does exceed any limits.

  4. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor

    How would you propose to see -0? as a 0 integer, or as a -0 double/float?

  5. stleary commented on Jan 27, 2016

    @stleary
    Owner

    Does anyone disagree with the problem statement:
    "JSON-Java is not following the spec when parsing the value, '-0'. It should be parsed as a number instead of a string."

  6. Merlinio commented on Jan 27, 2016

    @Merlinio

    @coderextreme I'm not sure if I understand what's the problem. You are saying that -0 is breaking schema. Which schema do you mean? According to information at JSON.org and there mentioned ECMA-404, such token should be considered as a number. So, the original appeal that tokenizer in JSON-java is processing such token as a string incorrectly is valid. Although the existence of something like negative zero is really strange.

  7. coderextreme commented on Jan 27, 2016

    @coderextreme
    Author

    Good question, looking at the schema, I either want an integer or a number. I would say integer (since integers are numbers), then parse -0.0 as a float/double.

    John

    On Jan 27, 2016, at 10:06 AM, johnjaylward [email protected] wrote:

    How would you propose to see -0? as a 0 integer, or as a -0 double/float?

    —
    Reply to this email directly or view it on GitHub #187 (comment).

  8. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor

    @Ronon-Dex when performing math with doubles and floats, a -0.0 is a possible value. I don't see it's existence as strange

    @stleary I believe it should be parsed as a number. In both specs mentioned in the readme, it should be a number and not a string. I'm working on a PR right now with test cases included

  9. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor

    Also, I don't believe this is a problem in the JSONTokener. It treats everything as a string value until it's passed up to the JSONObject.stringToValue method. The PR I'm creating will only have changes in that method.

  10. stleary commented on Jan 27, 2016

    @stleary
    Owner

    @johnjaylward Thanks, I will work on the unit test side.

  11. Merlinio commented on Jan 27, 2016

    @Merlinio

    @johnjaylward Yes, I agree with you. I didn't speak about the floating points. I'm thinking about negative integer zero but that's not the subject. Nevermind ;-)

    @stleary I agree with John. This should be parsed as a number.

  12. coderextreme commented on Jan 27, 2016

    @coderextreme
    Author

    @Ronon-Dex it's breaking the org.everit json-schema package, everit-org/json-schema#25 It's the only Java JSON schema validator published on json-schema.org which hasn't been abandoned.

  13. coderextreme commented on Jan 27, 2016

    @coderextreme
    Author

    Sorry I can't get a better URL for you to look at. It's local to github. And I don't really know markdown.

    Here's the non-issue link: https://github.com/everit-org/json-schema

  14. added a commit that references this issue on Jan 27, 2016
    07b2d65
  15. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor

    @stleary I'll leave the test cases to you as requested. the linked issue to the other project has some test data in it already if you want

  16. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor

    oh wait. I made an error... that's what I get for not having a test case

  17. stleary commented on Jan 27, 2016

    @stleary
    Owner

    @johnjaylward Feel free to propose test cases as well, if so inclined. I am a bit behind schedule with end-of-sprint tasks.

  18. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor

    Will do. although your new test project layout broke my submodule config. No need to change it though. I'll just switch how mine is configured

  19. stleary commented on Jan 27, 2016

    @stleary
    Owner

    Sorry about that, still a work in progress. build.gradle is defective as well.

  20. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor

    ok, submitted test cases as well.

  21. erosb commented on Jan 27, 2016

    @erosb
    Contributor

    Hello @stleary , @johnjaylward ,

    The JSON Schema specification makes a distinction between "number" and "integer", and it would be easier for me in my implementation to support these if -0 would be an integer and -0.0 would be a double. If -0 would be returned as a double, then probably the validator wouldn't be able to determine if it was -0 or -0.0 in the original JSON string (and it makes a difference during validation).

    Thank you.

  22. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor

    Mathematically, you would only encounter a -0 when working with doubles/floats. Most computer systems do not use one's complement for integer calculations and thus would only be seen as a product of a function using float or double precision numbers.

    If everyone agrees that -0 should be treated as int(0), then I'm fine with it. I just don't see how you would get a -0 to show up in JSON without it being from a double precision calculation

  23. erosb commented on Jan 27, 2016

    @erosb
    Contributor

    @johnjaylward that is probably true. In the original issue created by @coderextreme , he is also working with doubles when encountering the -0 literal.

  24. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor

    Just to clarify further, if I convert this to an Integer instead of a Double, the sign would be lost since Java integers are 2's compliment (no negative 0)

  25. erosb commented on Jan 27, 2016

    @erosb
    Contributor

    Ok, I'm fine with it :)

  26. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor

    @stleary I did not check the XML components to see if they need to be updated. Do you want me to verify those as well?

  27. stleary commented on Jan 27, 2016

    @stleary
    Owner

    @johnjaylward Yes, thanks, for the sake of consistent handling of -0/-0.0 wherever they are encountered.

  28. johnjaylward commented on Jan 27, 2016

    @johnjaylward
    Contributor

    ok, updated the PR both here and in the test bench

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