fix deserialize error with invalid map type

This commit is contained in:
appflowy 2021-09-22 15:02:55 +08:00
parent 79560dd161
commit 47f3a187c4

View File

@ -71,7 +71,6 @@ impl<'de> Deserialize<'de> for Attributes {
{
let mut attributes = Attributes::new();
while let Some(key) = map.next_key::<AttributeKey>()? {
log::warn!("{:?}", key);
let value = map.next_value::<AttributeValue>()?;
attributes.add_kv(key, value);
}
@ -103,10 +102,7 @@ impl<'de> Deserialize<'de> for AttributeValue {
struct AttributeValueVisitor;
impl<'de> Visitor<'de> for AttributeValueVisitor {
type Value = AttributeValue;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
//
formatter.write_str("bool, usize or string")
}
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.write_str("bool, usize or string") }
fn visit_bool<E>(self, value: bool) -> Result<Self::Value, E>
where
E: de::Error,
@ -190,6 +186,16 @@ impl<'de> Deserialize<'de> for AttributeValue {
{
Ok(AttributeValue(None))
}
fn visit_map<A>(self, map: A) -> Result<Self::Value, A::Error>
where
A: MapAccess<'de>,
{
// https://github.com/serde-rs/json/issues/505
let mut map = map;
let value = map.next_value::<AttributeValue>()?;
Ok(value)
}
}
deserializer.deserialize_any(AttributeValueVisitor)