Skip to content

serde_json::from_value fails on sequence deserialization for a String array #871

@dr-orlovsky

Description

@dr-orlovsky

serde_json::from_value fails on sequence deserialization for a String array previously created by serde_json::to_value with invalid type: string \"...\", expected a borrowed string error. The reason is this code fragment

json/src/value/de.rs

Lines 336 to 352 in 2733e63

fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
self.deserialize_string(visitor)
}
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
match self {
#[cfg(any(feature = "std", feature = "alloc"))]
Value::String(v) => visitor.visit_string(v),
_ => Err(self.invalid_type(&visitor)),
}
}

where 349 calls visitor.visit_string(v) while v is a StrVisitor and not StringVisitor object. This object fails to process String and not &str with the error above returned from here:
https://github.com/serde-rs/serde/blob/7e19ae8c9486a3bbbe51f1befb05edee94c454f9/serde/src/de/mod.rs#L1476-L1492

I do not familiar with serde/serde_json internals and can't propose a proper fix here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions