Fix serializing json objects

This commit is contained in:
Erick Tryzelaar
2015-03-03 21:55:48 -08:00
parent 6382441f2e
commit b2f52df5ff
2 changed files with 25 additions and 25 deletions
+7 -5
View File
@@ -8,7 +8,7 @@ use de;
use ser;
use super::error::Error;
#[derive(PartialEq)]
#[derive(Clone, PartialEq)]
pub enum Value {
Null,
Bool(bool),
@@ -61,6 +61,7 @@ impl fmt::Debug for Value {
}
}
#[derive(Debug)]
enum State {
Value(Value),
Array(Vec<Value>),
@@ -227,21 +228,22 @@ impl ser::Visitor for Serializer {
V: ser::Serialize,
{
try!(key.visit(self));
try!(value.visit(self));
let key = match self.state.pop().unwrap() {
State::Value(Value::String(value)) => value,
_ => panic!(),
state => panic!("expected key, found {:?}", state),
};
try!(value.visit(self));
let value = match self.state.pop().unwrap() {
State::Value(value) => value,
_ => panic!(),
state => panic!("expected value, found {:?}", state),
};
match *self.state.last_mut().unwrap() {
State::Object(ref mut values) => { values.insert(key, value); }
_ => panic!(),
ref state => panic!("expected object, found {:?}", state),
}
Ok(())