You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To trigger this issue, you need to create a struct containing at least two fields:
the first field is optional with the default value of None, and the created instance contains the None variant for this field.
the optional field is not the last one in the structure.
try to deserialize some content serialized with rmp::to_vec (not rmp::to_vec_named).
use serde::{Serialize,Deserialize};fnmain(){let record = Record::default();println!("{:?}", record);let encoded = rmp_serde::to_vec(&record).unwrap();// this will fail later with decoding// let encoded = rmp_serde::to_vec_named(&record).unwrap(); // note: this won't fail with decodingprintln!("{:?}", encoded);let decoded:Record = rmp_serde::from_slice(&encoded).unwrap();println!("{:?}", decoded);}#[derive(Serialize,Deserialize,Debug)]structRecord{#[serde(default)]#[serde(skip_serializing_if = "Option::is_none")]optional_field:Option<u8>,// note: this isn't the last fieldanother_field:u8,// note: you need to place this after 'optional_field' to trigger this issue}implDefaultforRecord{fndefault() -> Self{Self{optional_field:None,// note: replacing with Some(value) won't trigger this issueanother_field:10,}}}
Testing Platform:
Linux Mint 20.2 (x86-64)
cargo 1.58.0
rustc 1.58.1
serde = "1.0.136"
rmp-serde = "1.0.0"
The text was updated successfully, but these errors were encountered:
jsprog
changed the title
rmp_serde::to_vec is failing to deserialize skipped default None variant
Failing to deserialize skipped default None variant for content generated by rmp_serde::to_vec
Mar 23, 2022
To trigger this issue, you need to create a
struct
containing at least two fields:None
, and the created instance contains theNone
variant for this field.rmp::to_vec
(notrmp::to_vec_named
).Testing Platform:
The text was updated successfully, but these errors were encountered: