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

Allow differentiating between number and integer #218

Closed
joca-bt opened this issue Feb 27, 2020 · 9 comments
Closed

Allow differentiating between number and integer #218

joca-bt opened this issue Feb 27, 2020 · 9 comments

Comments

@joca-bt
Copy link

joca-bt commented Feb 27, 2020

Although integer is not part of the JSON Schema data model (from the spec: Note that JSON Schema vocabularies are free to define their own extended type system. This should not be confused with the core data model types defined here. As an example, "integer" is a reasonable type for a vocabulary to define as a value for a keyword, but the data model makes no distinction between integers and other numbers.) in practice it is heavily used in vocabulary and allowed as a type by several applications, libraries, and frameworks (e.g. http://fasterxml.github.io/jackson-core/javadoc/2.10/com/fasterxml/jackson/core/JsonToken.html). For this reason, it would be helpful to be able distinguish between them, i.e. having an isNumber() and an isInteger() in JsonAssert.

@lukas-krecan
Copy link
Owner

lukas-krecan commented Feb 28, 2020

Thanks for feedback. It's a bit tricky, since JsonUnit is able to parse JSON using different libraries and not all of them expose such information. Will take a look at it.

@lukas-krecan
Copy link
Owner

Would this work for you https://github.com/lukas-krecan/JsonUnit/pull/220/files?

@joca-bt
Copy link
Author

joca-bt commented Feb 28, 2020

It would!

@lukas-krecan
Copy link
Owner

Just to make sure that I understand you correctly, would you consider "1.0" to be an integer or not? In other words, do you want to check absence of the decimal point or that the number is integer?

@joca-bt
Copy link
Author

joca-bt commented Feb 28, 2020

1.0 in the json body would be a number and not an integer.

@lukas-krecan
Copy link
Owner

Ok, and what about "1e3"?

@lukas-krecan
Copy link
Owner

I think this should do

    /**
     * Asserts that the value is an integer. 1 is an integer 1.0, 1.1, 1e3, 1e0, 1e-3 is not.
     */
    public BigIntegerAssert isIntegralNumber()

@joca-bt
Copy link
Author

joca-bt commented Feb 29, 2020

That would be great!

lukas-krecan added a commit that referenced this issue Feb 29, 2020
#218 Allow differentiating between number and integer
@lukas-krecan
Copy link
Owner

Released as 2.14.0

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