Allow json missing fields to be treated as a null

Closes #34.
This commit is contained in:
Erick Tryzelaar
2015-03-12 20:44:16 -07:00
parent 5dd53e7ea3
commit dc87288f48
5 changed files with 82 additions and 4 deletions
+25
View File
@@ -553,6 +553,31 @@ impl<'a> de::MapVisitor for MapDeserializer<'a> {
}
}
fn missing_field<V>(&mut self, _field: &'static str) -> Result<V, Error>
where V: de::Deserialize,
{
// See if the type can deserialize from a unit.
struct UnitDeserializer;
impl de::Deserializer for UnitDeserializer {
type Error = Error;
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
visitor.visit_unit()
}
fn visit_option<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
visitor.visit_none()
}
}
Ok(try!(de::Deserialize::deserialize(&mut UnitDeserializer)))
}
fn size_hint(&self) -> (usize, Option<usize>) {
(self.len, Some(self.len))
}