Skip to content

Nesting types implementing De/SerializeAs with serde_as #480

Answered by jonasbb
spikespaz asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, if you want to get into more complicated implementations, I encourage you to read the documentation of SerializeAs. It contains some examples which show how to implement the code.

The problem is that you are asking serde_json to deserialize a Vec<Base62Encoded<u64>>, but you need to produce a Vec<u64>. You need to mark in your type signature, that the T inside JsonString is different than the T you return. You turn the JsonString into a container-like type.

I would be happy to accept a PR which changes the JsonString in this crate to allow for this added flexibility.

pub struct JsonString<T>(PhantomData<T>);

impl<T, TAs> SerializeAs<T> for JsonString<TAs>
where
    TAs: SerializeAs<T>,

Replies: 1 comment 10 replies

Comment options

You must be logged in to vote
10 replies
@spikespaz
Comment options

@jonasbb
Comment options

@spikespaz
Comment options

@spikespaz
Comment options

@jonasbb
Comment options

Answer selected by jonasbb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants