Skip to content

Deserialize and serialize quantities as integers #436

@marcospb19

Description

@marcospb19

Some JSON bodies pass integers as strings.

{
    "unit": "lovelace",
    "quantity": "500000"
}

Here's the current struct for this (simplified):

#[derive(Deserialize)]
pub struct Amount {
    pub unit: String,
    pub quantity: String,
}

It must be changed to:

#[derive(Deserialize)]
pub struct Amount {
    pub unit: String,
    #[serde_hacks]
    pub quantity: Integer,
}

Where Integer is our type alias for i128 and serde_hacks is the custom deserialization for that specific field.

Some options to customize this:

  1. https://docs.rs/serde_with/1.10.0/serde_with/#displayfromstr
  2. https://serde.rs/variant-attrs.html# (+ https://docs.rs/serde/1.0.130/serde/de/trait.Error.html)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions