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

Document how to deserialize from a prefix of an io::Read without blocking until EOF #522

Open
dtolnay opened this issue Mar 11, 2019 · 0 comments
Labels

Comments

@dtolnay
Copy link
Member

dtolnay commented Mar 11, 2019

The behavior of serde_json::from_reader is that it expects the input stream to end after the deserialized object. If the stream contains trailing data, that is considered an error. If the stream does not end, such as in the case of a persistent socket connection, then from_reader would not return. This is the correct behavior for from_reader for example when deserializing from a File, in which we don't want to silently allow trailing garbage. It is possible instead to deserialize from a prefix of an input stream without looking for EOF by managing your own Deserializer:

let mut de = serde_json::Deserializer::from_reader(stream);
let t = T::deserialize(&mut de)?;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant