Rocket.rs route alternative to JsonValue

90 views Asked by At

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" ?

0

There are 0 answers