Hello, World! I have a JSON API returning numbers...
# serialization
b
Hello, World! I have a JSON API returning numbers, but apparently
kotlin.Number
is not Serializable. What's the easiest way to deal with this?
j
Use Double. Number is kinda useless
b
I guess I wanted to avoid Double because it's not precise... But actually all Longs can be represented as Doubles right? - no because Double and Long are both 64 bit
j
It's not safe to return a number in JSON that won't fit in a Double anyway
b
to be honest I wish the API in question would just distinguish integer and floating point fields 🙂. I ended up using Strings, with
isLenient
set to true, and decoding to the correct type on a higher layer (I guess I could have used a custom serializer but wanted to keep it simple.)