diff --git a/serde2/src/json/value.rs b/serde2/src/json/value.rs index 73bbeff8..803f3d41 100644 --- a/serde2/src/json/value.rs +++ b/serde2/src/json/value.rs @@ -104,12 +104,6 @@ impl ser::Visitor for Serializer { type Value = (); type Error = (); - #[inline] - fn visit_unit(&mut self) -> Result<(), ()> { - self.state.push(State::Value(Value::Null)); - Ok(()) - } - #[inline] fn visit_bool(&mut self, value: bool) -> Result<(), ()> { self.state.push(State::Value(Value::Bool(value))); @@ -158,6 +152,22 @@ impl ser::Visitor for Serializer { value.visit(self) } + #[inline] + fn visit_unit(&mut self) -> Result<(), ()> { + self.state.push(State::Value(Value::Null)); + Ok(()) + } + + #[inline] + fn visit_enum_unit(&mut self, _name: &str, variant: &str) -> Result<(), ()> { + let mut values = BTreeMap::new(); + values.insert(variant.to_string(), Value::Array(vec![])); + + self.state.push(State::Value(Value::Object(values))); + + Ok(()) + } + #[inline] fn visit_seq(&mut self, mut visitor: V) -> Result<(), ()> where V: ser::SeqVisitor, diff --git a/serde2/tests/test_json.rs b/serde2/tests/test_json.rs index 27dd2b25..8b759279 100644 --- a/serde2/tests/test_json.rs +++ b/serde2/tests/test_json.rs @@ -346,7 +346,6 @@ fn test_write_tuple() { */ } -/* #[test] fn test_write_enum() { test_encode_ok(&[ @@ -408,6 +407,7 @@ fn test_write_enum() { */ } +/* #[test] fn test_write_option() { test_encode_ok(&[