diff --git a/src/ser/mod.rs b/src/ser/mod.rs index 8130a8d..7162afa 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -400,6 +400,11 @@ impl<'ser, W: Write> serde::ser::Serializer for &'ser mut Serializer { mod tests { use super::*; use serde::Serialize; + use simple_logger::SimpleLogger; + + fn init_logger() { + SimpleLogger::new().with_utc_timestamps().init().unwrap(); + } #[test] fn test_serialize_struct() { @@ -447,4 +452,64 @@ mod tests { let got = String::from_utf8(buffer).unwrap(); assert_eq!(got, should_be); } + + #[test] + fn test_serialize_nested_structs() { + #[derive(Debug, Serialize, PartialEq)] + struct Outer { + a: Inner, + } + + #[derive(Debug, Serialize, PartialEq)] + struct Inner { + name: String, + } + + let coll = Outer { + a: Inner { + name: "42".to_owned(), + }, + }; + + let str = to_string(&coll).unwrap(); + println!("str={:?}", str); + } + #[test] + fn test_serialize_nested_collection() { + init_logger(); + + #[derive(Debug, Serialize, PartialEq)] + struct OuterCollection { + a: Vec, + } + + #[derive(Debug, Serialize, PartialEq)] + struct A { + name: String, + } + + let coll = OuterCollection { + a: vec![A { + name: "42".to_owned(), + }], + }; + + let str = to_string(&coll).unwrap(); + println!("str={:?}", str); + } + + #[test] + fn test_serialize_vector() { + #[derive(Debug, Serialize, PartialEq)] + struct OuterCollection { + a: Vec, + } + + let coll = OuterCollection { + a: vec!["42".to_owned()], + }; + + let str = to_string(&coll).unwrap(); + println!("str={:?}", str); + } } diff --git a/src/ser/seq.rs b/src/ser/seq.rs index 1681534..caf7cc5 100644 --- a/src/ser/seq.rs +++ b/src/ser/seq.rs @@ -1,5 +1,6 @@ use super::Serializer; use crate::error::{Error, Result}; +use log::debug; use serde::ser::Serialize; use std::io::Write; @@ -22,8 +23,10 @@ impl<'ser, W: 'ser + Write> serde::ser::SerializeSeq for SeqSeralizer<'ser, W> { T: ?Sized + Serialize, { let must_close_tag = self.ser.build_start_tag()?; + debug!("start, must_close_tag={:?}", must_close_tag); value.serialize(&mut *self.ser)?; if must_close_tag { + debug!("end"); self.ser.end_tag()?; self.ser.reopen_tag()?; } @@ -31,7 +34,9 @@ impl<'ser, W: 'ser + Write> serde::ser::SerializeSeq for SeqSeralizer<'ser, W> { } fn end(self) -> Result<()> { - self.ser.abandon_tag()?; + debug!("end"); + // TODO: Commenting this out fixes it, but unsure why + // self.ser.abandon_tag()?; Ok(()) } }