This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 157
Integers get serialized as floats by to_value #98
Comments
I was not able to reproduce this. Here is what I tried: [dependencies]
serde = "1.0"
serde_derive = "1.0"
serde_yaml = "0.7" #[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_yaml;
use serde_yaml::Value;
#[derive(Serialize, Deserialize, Debug)]
struct Monitor {
spoof_host: Option<String>,
shell_command: String,
max_check_attempts: usize,
notify: Option<Value>,
run_every: usize,
}
fn main() {
println!("{}", serde_yaml::to_string(&Monitor {
spoof_host: None,
shell_command: "sh".to_owned(),
max_check_attempts: 60,
notify: None,
run_every: 60,
}).unwrap());
} ---
spoof_host: ~
shell_command: sh
max_check_attempts: 60
notify: ~
run_every: 60 Can you spot anything different from the way this happens in your code? |
Hi David, Thank you for the quick response. I guess I have some differences in my code & it might be because I'm not exactly sure what I'm doing. Within my script, I take Monitor type & reconvert it back to a Value to be help within a BTreeMap. The problem seems to happen when I convert it back from a Monitor to a Value. So within two lines of the code I placed:
and in the output, I get:
and
I guess the main difference is using "serde_yaml::to_value" instead of "to_string" like you are. |
dtolnay
changed the title
Int's deserialzied as floats
Integers get serialized as floats by to_value
Aug 22, 2018
Thanks! I released 0.8.0 with a fix. |
I saw that.
I updated cargo for the change and can confirm that this fixes the issue. Thank you very much for turning this around so quickly.
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
…On August 22, 2018 2:03 PM, David Tolnay ***@***.***> wrote:
Thanks! I released 0.8.0 with a fix.
—
You are receiving this because you authored the thread.
Reply to this email directly, [view it on GitHub](#98 (comment)), or [mute the thread](https:/notifications/unsubscribe-auth/AADxqJxXl0-vWx12A39TyFjhH13OEMiFks5uTbj4gaJpZM4WH9WU).
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi, I'm not sure what I'm doing wrong there, but I would appreciate some help.
I've got this struct that that serializes data just fine:
When viewing the data becoming a Monitor datatype, the data is in its propper format (int):
However, when writing the data to a file, the numbers become floats:
This is also true for the "max_check_attemps" field as well. Any help with this would be appreciated. Please let me know if I can help in anyway, I'm happy to share more information if requested.
Thanks in advance.
The text was updated successfully, but these errors were encountered: