Skip to content

What is the best practice of using Json<T> to parse req.body #1921

Answered by jebrosen
duskmoon314 asked this question in Questions
Discussion options

You must be logged in to vote

This is a current limitation of serde's zero-copy deserialization: if the input contains escape sequences, there is nowhere for serde to put the decoded string such that an &'r str could refer to it. A Cow<'r, str> or String should work; see also serde-rs/json#742.

I tried to find the JSON example on GitHub, but it has been delated in v0.5-rc.

It hasn't been deleted entirely, but moved to https://github.com/SergioBenitez/Rocket/blob/v0.5-rc/examples/serialization/src/json.rs . (I think there are still a few broken links floating around that are fixed in the repository but not yet published). That example uses Cow<'r, str>, which ought to work for you as well.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@duskmoon314
Comment options

Answer selected by duskmoon314
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants