Skip to content

Commit

Permalink
fix: added default for i128 to string
Browse files Browse the repository at this point in the history
  • Loading branch information
paulobressan committed Oct 5, 2023
1 parent 27fb7e8 commit 46d2ca7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Display;

use merge::Merge;

use serde::{Deserialize, Serialize};
use serde::{de::Error as DeError, Deserialize, Deserializer, Serialize, Serializer};
use serde_json::Value as JsonValue;

use strum_macros::Display;
Expand All @@ -29,6 +29,8 @@ pub enum Era {
pub enum MetadatumRendition {
MapJson(JsonValue),
ArrayJson(JsonValue),
#[serde(serialize_with = "serialize_int_scalar")]
#[serde(deserialize_with = "deserialize_int_scalar")]
IntScalar(i128),
TextScalar(String),
BytesHex(String),
Expand Down Expand Up @@ -374,3 +376,18 @@ pub struct Event {

pub fingerprint: Option<String>,
}

fn serialize_int_scalar<S>(value: &i128, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
value.to_string().serialize(serializer)
}

fn deserialize_int_scalar<'de, D>(deserializer: D) -> Result<i128, D::Error>
where
D: Deserializer<'de>,
{
let value: String = Deserialize::deserialize(deserializer)?;
Ok(value.parse().map_err(DeError::custom)?)
}

0 comments on commit 46d2ca7

Please sign in to comment.