Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error deserializing Owned data #34

Closed
Jusduil opened this issue Jan 12, 2023 · 0 comments · Fixed by #35
Closed

Error deserializing Owned data #34

Jusduil opened this issue Jan 12, 2023 · 0 comments · Fixed by #35

Comments

@Jusduil
Copy link
Contributor

Jusduil commented Jan 12, 2023

Hello,

When deserialize Language from owned data (example with serde_json::from_reader or serde_json::from_value), deserializer fail.

dbg!(serde_json::from_value::<Language>(serde_json::json!("fr")))
= Err(
    Error("invalid type: string \"fr\", expected borrowed str or bytes", line: 0, column: 0),
)

This is because only visit_borrowed_str and visit_borrowed_bytes is implemented on Visitor.

    fn visit_borrowed_str<E>(self, v: &'a str) -> Result<Self::Value, E>
    where
        E: serde::de::Error,
    { ... }

    fn visit_borrowed_bytes<E>(self, v: &'a [u8]) -> Result<Self::Value, E>
    where
        E: serde::de::Error,
    { ... }

I propose to replace this implementation to implement visit_str and visit_bytes, this two methods accept data borrowed and owned. The default implementation of borrowed version forward to not borrowed version.

Thank you for considering this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant