cognitect / transit-cljs

Transit for ClojureScript
http://transit-format.org
Apache License 2.0
323 stars 20 forks source link

Encoding for float ground type #54

Closed dustingetz closed 4 years ago

dustingetz commented 4 years ago

In Javascript platform I would like to make {:person/weight 200.0} transmit as a float, not an int. By default Javascript will turn that to Number: 200 and encode an int, JVM will decode int and JVM doesn't have the context to know that it should be coerced to float. It is the client's job to transmit the data properly and deal with platform quirks at the point that the value escapes the platform.

Forgoing the above, I would like to argue that this is a foundational flaw in transit as argued here on ask.clojure.org

dustingetz commented 4 years ago

So this isn't an "issue" related to javascript platform, this behavior is introduced by the JSON encoding strategy choosing to use JSON Number for transport. On the JVM reader, the json representation makes it way into Jackson which parses a VALUE_NUMBER_INT if there is no decimal. The tradeoff here is reasonable but the unexpected cost to me is that in this worldview, (= 1 1.0) and it introduces app complexity to deal with this.