esensar/kotlinx-serialization-msgpack

When strictTypes is false support parsing all number types for the requested type

rubixhacker opened this issue · 2 comments

The service we are using msgpack with is using the smallest possible key to send the payload and will mix scalar and decimal types, for instance: instead of sending 0.0 as a float, it will send 0 as a byte. Right now when strict types is false it will only attempt to parse scalar types or decimal types based on the requested type but will fail if requesting a decimal type and the payload value is a scalar and vice-versa.

Another option would be add a serializer for Number that would try all number types.

Thank you for reporting this.

I am not sure what the behavior is for other formats when using kotlinx.serialization, but I believe that suggested behavior is probably right, since lossy conversion is to be expected when disabling strict types.

Feel free to open a PR if you wish to fix this yourself. If not, I will take it on as soon as I have the time.

Closed by #84