1

I changed my version of Rocket 0.4.2 to 0.5rc, and my Result<Json<JsonValue don't work, because is deprecated.

I don't find any informations about a new way to do it..

In my case, I want to send back a vector of a struct for my route (get all entity of my column).


#[rocket::get("/")]
fn read(connection: db::DbConn) -> Result<Json<Vec<Metric>>, Status> {
    Metric::get_all(&connection)
        .map(|item| Json(json!(item)))
        .map_err(|_| Status::NotFound);
}

My get_all method return a vector of Metric


    pub fn get_all(connection: &PgConnection) -> QueryResult<Vec<Metric>> {
        metrics::table.order(metrics::id).load::<Metric>(connection)
    }

But it's not working.. We have a solution to just tell to rocket that we send a "JsonValue" ?

jenoh
  • 165
  • 3
  • 17
  • 1
    What is the exact error you're getting? According to https://docs.rs/rocket/0.5.0-rc.1/rocket/serde/json/struct.Json.html, `Json` should work as long as `T: serde::Serialize`. Does `Metric` implement `Serialize`? Also your function has a semicolon at the end so it doesn't return anything. – Dogbert Apr 08 '22 at 13:23
  • What are your imports? Previously `Json` was provided by the `rocket_contrib` crate but in 5.0 it's in `rocket` directly – kmdreko Apr 08 '22 at 20:46

0 Answers0