Skip to content

PickFirst for the entire struct? #667

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

You must be logged in to vote

This is not possible, due to a couple of reasons. First, serde itself does not provide a way to redefine the derived implementations like this. There is no serde(with="") that you can put on a container.
Further, the logic here is circular. To deserialize a Foo you first try to deserialize a Foo, for that you first try to deserialize a Foo, etc. The inner deserializations will use the same trait implementation.

If you do not use the derived Deserialize implementation you can achieve what you want. Based on the serde string or struct example:

#[derive(Deserialize, Default, PartialEq, Debug)]
#[serde(remote = "Self")]
struct Foo {
    name: String,
    value: u32,
}

impl<'de> Deserialize<'de>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rlidwka
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