Skip to content

Commit 817cb7a

Browse files
committed
fix: serialize U256 as decimal
1 parent 7810b12 commit 817cb7a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/models/avatar.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use alloy::primitives::{Address, U256};
2-
use serde::Serialize;
2+
use serde::{Serialize, Serializer};
3+
34
use crate::services;
45

56
#[derive(Serialize)]
67
pub struct Avatar {
78
pub token_address: Address,
9+
#[serde(serialize_with = "serialize_u256_as_decimal")]
810
pub token_id: U256
911
}
1012

@@ -17,6 +19,13 @@ impl From<services::rpc::AvatarService::Avatar> for Avatar {
1719
}
1820
}
1921

22+
fn serialize_u256_as_decimal<S>(value: &U256, serializer: S) -> Result<S::Ok, S::Error>
23+
where
24+
S: Serializer,
25+
{
26+
serializer.serialize_str(&value.to_string())
27+
}
28+
2029
#[allow(clippy::module_name_repetitions)]
2130
#[derive(Serialize)]
2231
pub struct AvatarInfo {

0 commit comments

Comments
 (0)