Skip to main content

serialize

Function serialize 

Source
pub fn serialize<S: Serializer>(
    value: &Decimal,
    serializer: S,
) -> Result<S::Ok, S::Error>
Expand description

Serializes a decimal as a JSON number without changing its numeric value.

Checks the Number representation before serialization so to_value is also lossless. The full Decimal range requires serde_json/arbitrary_precision. Without that feature, scale is not preserved and output may use exponent notation. Check the receiving API’s numeric syntax before using this serializer for wire payloads.

Raw-token serializers can emit the full Decimal range directly to JSON text without arbitrary precision. Replacing them with this serializer can reject previously supported values unless serde_json/arbitrary_precision is enabled. Use super::serialize_decimal_as_str for portable string output.

§Errors

Returns an error if:

  • The enabled JSON representation would round the value.
  • Serialization fails.