You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So in essence the implementation is the same but two different code paths. So which one should the casual user of rust_decimal rely upon?
I am using serde-with-str feature but frankly I don't remember how and when I plugged it in. I think that there was no default serialization for Decimal in the past, maybe it was added recently? Anyhow that feels confusing that there are two individual code paths exist that ultimately do the same thing. Documentation isn't very helpful neither.
It does however seem that deserialization works differently, i.e rust_decimal::serde::str only accepts strings, but without it JSON strings, integers and floats are parsed into Decimal.
The text was updated successfully, but these errors were encountered:
serde-*(e.g. serde-str) features allow you to override the default (de-)serialization strategy globally. serde-with-* (e.g. `serde-with-str) features allow you to override the default (de-)serialization strategy on a case-by-case basis.
We would generally recommend using the serde-with-* features where possible.
As for which you want to use? That depends on how you want your types to be (de-)serialized.
Hi,
Today I wrote a struct with one field using
#[serde(with = "rust_decimal::serde::str")]
and the other not:Which surprise compiled. That begs the question what is going on with field a and b.
So I traced the execution and found that the field A is serialized with
rust_decimal::serde::str::serialize
:The field B is serialized using the following imp:
So in essence the implementation is the same but two different code paths. So which one should the casual user of
rust_decimal
rely upon?I am using
serde-with-str
feature but frankly I don't remember how and when I plugged it in. I think that there was no default serialization forDecimal
in the past, maybe it was added recently? Anyhow that feels confusing that there are two individual code paths exist that ultimately do the same thing. Documentation isn't very helpful neither.It does however seem that deserialization works differently, i.e
rust_decimal::serde::str
only accepts strings, but without it JSON strings, integers and floats are parsed intoDecimal
.The text was updated successfully, but these errors were encountered: