Skip to content

Deserializers composition #664

Answered by jonasbb
xamgore asked this question in Q&A
Nov 25, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Why are you deriving a wrong Deserialize implementation in the first place? If you want the enum to serialize into strings with decimal numbers, the Deserialize implementation should match that. The normal serde_derive is enough to achieve that:

#[repr(u8)]
#[derive(serde::Serialize)]
enum A {
    #[serde(rename = "12")]
    Variant = 12,
}

If you don't like the way JsonString is implemented, you could write something yourself. There is nothing in the serde_with crate, that will allow you to chain deserializing behavior like str -> u8 & u8 -> A.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@xamgore
Comment options

Answer selected by xamgore
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