浏览代码

fix deserialize error with invalid map type

appflowy 3 年之前
父节点
当前提交
47f3a187c4
共有 1 个文件被更改,包括 11 次插入5 次删除
  1. 11 5
      rust-lib/flowy-ot/src/core/attributes/attributes_serde.rs

+ 11 - 5
rust-lib/flowy-ot/src/core/attributes/attributes_serde.rs

@@ -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)