massa icon indicating copy to clipboard operation
massa copied to clipboard

Harmonize JSON response output for enums/structs

Open aoudiamoncef opened this issue 2 years ago • 0 comments

Actually, enum are serialized with Rust name :

{
  "content": {
...
    "op": {
      "Transaction": {
        "amount": "0.000950028",
        "recipient_address": "A1Czd9sRp3mt2KU9QBEEZPsYxRq9TisMs1KnV4JYCe7Z4AAVinq"
      }
    }
  },
...
}

It should be in snake case :

{
  "content": {
...
    "op": {
      "transaction": {
        "amount": "0.000950028",
        "recipient_address": "A1Czd9sRp3mt2KU9QBEEZPsYxRq9TisMs1KnV4JYCe7Z4AAVinq"
      }
    }
  },
...
}

Solution :

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum OperationType {
    /// transfer coins from sender to recipient
    Transaction {
        /// recipient address
        recipient_address: Address,
        /// amount
        amount: Amount,
    },
...
}

aoudiamoncef avatar Jul 12 '22 12:07 aoudiamoncef