'cannot find type `Json` in module `content` in rust rocket

Today when I using cargo cargo 1.59.0 (49d8809dc 2022-02-10) compile the rust rustc 1.59.0 (9d1b2106e 2022-02-23) project, shows error:

error[E0412]: cannot find type `Json` in module `content`
  --> src/common/util/model_convert.rs:35:50
   |
35 | pub fn box_rest_response<T>(data: T) -> content::Json<String> where T: Serialize + Default {
   |                                                  ^^^^ not found in `content`
   |
help: consider importing one of these items
   |
1  | use diesel::pg::types::sql_types::Json;
   |
1  | use diesel::types::Json;
   |
1  | use rocket::serde::json::Json;
   |

error[E0425]: cannot find function, tuple struct or tuple variant `Json` in module `content`
  --> src/common/util/model_convert.rs:41:21
   |
41 |     return content::Json(response_json);
   |                     ^^^^ not found in `content`

this is the code where going wrong:

use diesel::QueryResult;
use rocket::response::content;
use rocket::serde::json::serde_json;
use serde::Serialize;
use crate::model::response::api_response::ApiResponse;
use crate::model::response::pagination::Pagination;
use crate::model::response::pagination_response::PaginationResponse;

pub fn box_error_rest_response <T>(data: T, result_code: String, msg: String) -> content::Json<String> where T: Serialize + Default {
    let res = ApiResponse {
        result: data,
        statusCode: "200".to_string(),
        resultCode: result_code,
        msg
    };
    let response_json = serde_json::to_string(&res).unwrap();
    return content::Json(response_json);
}

the content::Json was come from rocket rocket = { version = "0.5.0-rc.1", features = ["json"] }. The public lib works fine in the past time, I did not know why come out this error today. what should I do to fixed this problem? I tried to make a minimal demo main.rs like this:

#[macro_use]
extern crate rocket;

use rocket::{Build, Rocket, routes};
use rocket::response::content;

#[launch]
async fn rocket() -> _ {
    build_rocket()
}

#[get("/health")]
pub fn health() -> content::Json<String> {
    return content::Json("ok".parse().unwrap());
}

fn build_rocket() -> Rocket<Build> {
    rocket::build()
        .mount("/actuator", routes![
            health
        ])
}

but it works fine and did not told that cannot find type Json in module content.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source