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
jw
01/17/2021, 5:03 PM
Use Double. Number is kinda useless
b
bod
01/17/2021, 5:19 PM
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
jw
01/17/2021, 6:43 PM
It's not safe to return a number in JSON that won't fit in a Double anyway
b
bod
01/17/2021, 11:06 PM
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.)