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
#[macro_use]externcrate serde_derive;externcrate serde;externcrate serde_json;externcrate serde_test;use serde_test::{assert_tokens,Token};#[derive(Serialize,Deserialize,Debug,PartialEq,Eq)]pubstructVecWrapper(pubVec<u8>);#[derive(Serialize,Deserialize,Debug,PartialEq)]#[serde(untagged)]pubenumEnum{Str(String),Vector(VecWrapper),Number(f64),Boolean(bool),Nil,Other,}fnmain(){let v = Enum::Vector(VecWrapper(vec![b'a', b'b', b'c']));let s = serde_json::to_string(&v).unwrap();println!("{:?}", s);let v_:Enum = serde_json::from_str(&*s).unwrap();assert_eq!(v, v_);assert_tokens(&v,&[Token::NewtypeStruct{name:"VecWrapper"},Token::Seq{len:Some(3)},Token::U8(97),Token::U8(98),Token::U8(99),Token::SeqEnd,],);}
With this, I get following output:
"[97,98,99]"
thread 'main' panicked at 'tokens failed to deserialize: data did not match any variant of untagged enum Enum', /home/mkpankov/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_test-1.0.42/src/assert.rs:192:19
I don't get why assert_tokens fails while serde_json::from_str succeeds. At the data model level everything should be the same?
I have the following test code:
With this, I get following output:
I don't get why
assert_tokens
fails whileserde_json::from_str
succeeds. At the data model level everything should be the same?Full project source.
The text was updated successfully, but these errors were encountered: