@@ -353,27 +353,30 @@ compile_error!(
353353/// You can also use [`#[serde_as(as = "...")]` attributes](https://docs.rs/serde_with/latest/serde_with/attr.serde_as.html)
354354/// as if `#[serde_as]` is added to the type (which is what actually happens under the hood of `#[near(serializers = [json])]` implementation).
355355///
356+ /// Note: When using the `abi` feature with base64/hex encoding, prefer the SDK's [`json_types`](crate::json_types)
357+ /// like [`Base64VecU8`](crate::json_types::Base64VecU8), which have full JSON Schema support.
358+ ///
359+ /// For hex encoding with ABI support, you can use `#[serde_as(as = "serde_with::hex::Hex")]` by enabling
360+ /// the `serde_with/schemars_1` feature in your `Cargo.toml` (this requires upgrading to schemars 1.x).
361+ ///
356362/// ```
357- /// # use std::{ collections::BTreeMap} ;
363+ /// # use std::collections::BTreeMap;
358364/// use near_sdk::{
359365/// near,
360366/// serde_json::json,
361- /// serde_with::{base64::Base64, hex::Hex, json::JsonString, DisplayFromStr},
367+ /// serde_with::{json::JsonString, DisplayFromStr},
368+ /// json_types::Base64VecU8,
362369/// };
363370///
364371/// #[near(serializers = [json])]
365372/// pub struct MyStruct {
366373/// #[serde_as(as = "DisplayFromStr")]
367374/// pub amount: u128,
368375///
369- /// #[serde_as(as = "Hex")]
370- /// pub hex_bytes: Vec<u8>,
371- ///
372- /// #[serde_as(as = "Base64")]
373- /// pub base64_bytes: Vec<u8>,
376+ /// pub base64_bytes: Base64VecU8,
374377///
375- /// #[serde_as(as = "BTreeMap<Hex , Vec<DisplayFromStr>>")]
376- /// pub collection: BTreeMap<Vec<u8> , Vec<u128>>,
378+ /// #[serde_as(as = "BTreeMap<DisplayFromStr , Vec<DisplayFromStr>>")]
379+ /// pub collection: BTreeMap<u128 , Vec<u128>>,
377380///
378381/// #[serde_as(as = "JsonString")]
379382/// pub json_string: serde_json::Value,
@@ -382,18 +385,16 @@ compile_error!(
382385/// # assert_eq!(
383386/// # serde_json::to_value(&MyStruct {
384387/// # amount: u128::MAX,
385- /// # hex_bytes: vec![0x1a, 0x2b, 0x3c],
386- /// # base64_bytes: vec![1, 2, 3],
387- /// # collection: [(vec![0x1a, 0x2b, 0x3c], vec![u128::MAX])].into(),
388+ /// # base64_bytes: Base64VecU8::from(vec![1, 2, 3]),
389+ /// # collection: [(u128::MAX, vec![100, 200, u128::MAX])].into(),
388390/// # json_string: json!({"key": "value"}),
389391/// # })
390392/// # .unwrap(),
391393/// # json!({
392394/// # "amount": "340282366920938463463374607431768211455",
393- /// # "hex_bytes": "1a2b3c",
394395/// # "base64_bytes": "AQID",
395396/// # "collection": {
396- /// # "1a2b3c ": ["340282366920938463463374607431768211455"],
397+ /// # "340282366920938463463374607431768211455 ": ["100", "200", "340282366920938463463374607431768211455"],
397398/// # },
398399/// # "json_string": "{\"key\":\"value\"}",
399400/// # })
0 commit comments