Open irigarae opened 6 months ago
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
thanks for the info, this should be fixed.
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: