use smartstring's deserializer to support non borrowed strings
The map visitor for Dynamic was expecting a &str for the key, but the serde_json deserializer internally uses a Cow string, which can be Borrowed or Owned. In the case of Owned, the serde_json key deserializer is calling visit_string on the Visitor, which for &str will result in the error: Error("invalid type: string \"a\", expected a borrowed string", line: 0, column: 0) smartstring actually has its own Visitor implementation that handles both cases, so we can use it instead of an explicit conversion.
This commit is contained in:
@@ -143,8 +143,8 @@ impl<'d> Visitor<'d> for DynamicVisitor {
|
||||
fn visit_map<M: serde::de::MapAccess<'d>>(self, mut map: M) -> Result<Self::Value, M::Error> {
|
||||
let mut m = crate::Map::new();
|
||||
|
||||
while let Some((k, v)) = map.next_entry::<&str, _>()? {
|
||||
m.insert(k.into(), v);
|
||||
while let Some((k, v)) = map.next_entry()? {
|
||||
m.insert(k, v);
|
||||
}
|
||||
|
||||
Ok(m.into())
|
||||
|
Reference in New Issue
Block a user