-
-
Notifications
You must be signed in to change notification settings - Fork 796
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
Can not parse enum number #1162
Comments
That error message is pretty bad... I think what you're seeing is JSON does not differentiate between different number types and as a compromise between JSON's notion of numbers and Rust's notion of numbers serde_json treats all nonnegative integers as u64 and all negative integers as i64. It should work if we also provide a fn visit_u64<E>(self, value: u64) -> Result<$name, E>
where E: serde::de::Error
{
self.visit_i64(value as i64)
} |
@dtolnay yes, this works. However, this is not understandable at a glance. I suggest you commenting this behavior on the same |
@dtolnay I am going to check whether it is possible to do this via a procedural macro. If it is so, I'd do this in my https://docs.rs/serde-aux/0.3.0/serde_aux/macro.serde_aux_enum_number_declare.html However, of course, it should be done as a procedural macro in my opinion. |
Thanks! I filed serde-rs/serde-rs.github.io#69 to follow up on showing how to handle a mix of positive and negative enum values in that example. |
I have tried to parse a enum with numbers and it did not work for me (playground).
The error is very strange:
What's wrong?
P.S. Even original docs in
serde.rs
fail if I changeu64
toi64
in the deserialize method (playground).The text was updated successfully, but these errors were encountered: