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
Comments
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. |
Would this work for you https://github.com/lukas-krecan/JsonUnit/pull/220/files? |
It would! |
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? |
1.0 in the json body would be a number and not an integer. |
Ok, and what about "1e3"? |
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() |
That would be great! |
#218 Allow differentiating between number and integer
Released as 2.14.0 |
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 anisInteger()
inJsonAssert
.The text was updated successfully, but these errors were encountered: