-
-
Notifications
You must be signed in to change notification settings - Fork 777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to define integer tag in enum? #2252
Comments
Serde's enum variant serializers rely on strings1 and there's no way around that without modifying serde_json2 in your case. You will probably have to implement the (de)serialization of For instance, for impl Serialize for Block {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer
{
#[derive(Serialize)]
#[serde(rename = "Block")]
struct AdjTagged<T> {
t: u8,
c: T,
}
match self {
Block::Para(field) => AdjTagged { t: 1, c: field }.serialize(serializer),
Block::Str(field) => AdjTagged { t: 2, c: field }.serialize(serializer),
}
}
} Footnotes |
Duplicate of #745 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://serde.rs/enum-representations.html#adjacently-tagged
{"t": "Str", "c": "the string"}
➝{"t": 1, "c": "the string"}
{"t": "Para", "c": [{...}, {...}]}
➝{"t": 2, "c": [{...}, {...}]}
The text was updated successfully, but these errors were encountered: