Skip to content

Commit 36cd0ce

Browse files
committed
Fix struct_variant serialization to match serde_json's output
1 parent 6756418 commit 36cd0ce

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/ser/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,12 @@ where
323323
self,
324324
_name: &'static str,
325325
_variant_index: u32,
326-
_variant: &'static str,
326+
variant: &'static str,
327327
_len: usize,
328328
) -> Result<Self::SerializeStructVariant> {
329-
self.buf.push(b'{')?;
329+
self.buf.extend_from_slice(b"{\"")?;
330+
self.buf.extend_from_slice(variant.as_bytes())?;
331+
self.buf.extend_from_slice(b"\":{")?;
330332

331333
Ok(SerializeStructVariant::new(self))
332334
}
@@ -622,6 +624,6 @@ mod tests {
622624
}
623625
let a = A::A { x: 54, y: 720 };
624626

625-
assert_eq!(&*crate::to_string::<N, _>(&a).unwrap(), r#"{"x":54,"y":720}"#);
627+
assert_eq!(&*crate::to_string::<N, _>(&a).unwrap(), r#"{"A":{"x":54,"y":720}}"#);
626628
}
627629
}

src/ser/struct_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ where
9797
}
9898

9999
fn end(self) -> Result<Self::Ok> {
100-
self.ser.buf.push(b'}')?;
100+
self.ser.buf.extend_from_slice(b"}}")?;
101101
Ok(())
102102
}
103103
}

0 commit comments

Comments
 (0)