- 
                Notifications
    
You must be signed in to change notification settings  - Fork 209
 
Description
Lines 36 to 55 in b157ab0
| #[cfg(feature = "decimal")] | |
| #[cfg(not(feature = "f32_float"))] | |
| Union::Decimal(ref x, ..) => { | |
| use rust_decimal::prelude::ToPrimitive; | |
| match x.to_f64() { | |
| Some(v) => ser.serialize_f64(v), | |
| None => ser.serialize_str(&x.to_string()), | |
| } | |
| } | |
| #[cfg(feature = "decimal")] | |
| #[cfg(feature = "f32_float")] | |
| Union::Decimal(ref x, ..) => { | |
| use rust_decimal::prelude::ToPrimitive; | |
| match x.to_f32() { | |
| Some(v) => ser.serialize_f32(v), | |
| _ => ser.serialize_str(&x.to_string()), | |
| } | |
| } | 
This converts a Decimal to a float, which is an issue for roundtripping serialized to deserialized and back.
The issue where this appeared for me is:
I have an ID which gets correctly parsed from a blob of data (with deserializing a map of Dynamic) to a Decimal, which is enabled as a feature. But when sending a serialized blob again, where that Decimal is a part of, the Serialize implementation of Dynamic causes it to be serialized as f64.
You mentioned in #587 (comment) that one can consider such numbers as i64 as well, but that does not work with serialization and deserialization, if one of that converts to float.
Do you know of a way how I can make it to serialize as a integer number? Is there currently a way with rhai that I am missing?