We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Per the json schema specification integers also accept floating point numbers with zero fractional part:
Numbers with a zero fractional part are considered integers: 1.0 ;; compliant with schema { "type": "integer" }
Numbers with a zero fractional part are considered integers:
1.0 ;; compliant with schema { "type": "integer" }
This breaks a bit when decoding with a json-transformer.
(m/validate :int (m/decode :int 3.0 mt/json-transformer)) #_=> false
I think it would be a nice addition to the json-decoders:
;; just an example, not taking into account clj/cljs nor NaN, etc. (defn -float->long [x] (if (and (float? x) (zero? (rem x 1))) (long x) x)) (m/validate :int (m/decode :int 3.0 (mt/transformer {:decoders {:int -float->long}}))) #_=> true ;; same example (m/decode [:int {:decode/json -float->long}] 3.0 mt/json-transformer) #_=> 3 (m/decode [:int {:decode/json -float->long}] 3.2 mt/json-transformer) #_=> 3.2
The text was updated successfully, but these errors were encountered:
thanks for the info, this should be fixed.
Sorry, something went wrong.
feat: json-transformer decodes 123.0 into 123 for int schemas
aa4184c
fixes #986
Successfully merging a pull request may close this issue.
Per the json schema specification integers also accept floating point numbers with zero fractional part:
This breaks a bit when decoding with a json-transformer.
I think it would be a nice addition to the json-decoders:
The text was updated successfully, but these errors were encountered: