Function expect_number_as_string_or_null

Source
pub fn expect_number_as_string_or_null<'a>(
    token: Option<Result<Token<'a>, DeserializeError>>,
    input: &'a [u8],
) -> Result<Option<&'a str>, DeserializeError>
Expand description

Expects a Token::ValueNumber or Token::ValueNull, and returns the number as a string to preserve arbitrary precision.

This function extracts the raw JSON number string without converting it to u64/i64/f64, which would cause precision loss for numbers larger than those types can represent. This is essential for BigInteger and BigDecimal support.

§Arguments

  • token - The token to extract the number from
  • input - The original JSON input bytes (needed to extract the raw number string)

§Returns

  • Ok(Some(string)) - The number as a string slice
  • Ok(None) - If the token is null
  • Err - If the token is not a number or null