Actix-web JSON request body

See this comment about an error with deserializing a JSON request body.
What do I need to do to turn dog into an instance of the Dog struct?
https://github.com/mvolkmann/rust-actix-web-demo/blob/master/src/main.rs#L51

You have a Json<Dog> and you want a Dog, so you should go look up the documentation for the Json<T> type: actix_web::web::Json - Rust

The first method in the docs looks useful:

impl<T> Json<T> {
    /// Deconstruct to an inner value
    pub fn into_inner(self) -> T;
}
1 Like

Thanks! I really do hope that soon I reach the point that I am able to find the answers to my questions on my own. Admittedly after about six weeks with Rust I am still struggling to do that. I find it interesting that actix_web::web::Json only has one method, but they chose not to show an example of using it in the example code at the top of this page. I assume the example they do show indicates that you do not need to use the into_inner method to get the values of individual properties.

The Json type implements Deref and DerefMut which allows you to immutably and mutably borrow the thing inside the Json directly on the Json, but you need into_inner to get ownership of the inner value.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.