mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-29 00:00:18 +02:00
Add support for returning pretty JSON response in axum_extra::response::ErasedJson (#662)
This commit is contained in:
@@ -33,10 +33,15 @@ use serde::Serialize;
|
||||
pub struct ErasedJson(serde_json::Result<Vec<u8>>);
|
||||
|
||||
impl ErasedJson {
|
||||
/// Create an `ErasedJson` by serializing a value.
|
||||
/// Create an `ErasedJson` by serializing a value with the compact formatter.
|
||||
pub fn new<T: Serialize>(val: T) -> Self {
|
||||
Self(serde_json::to_vec(&val))
|
||||
}
|
||||
|
||||
/// Create an `ErasedJson` by serializing a value with the pretty formatter.
|
||||
pub fn pretty<T: Serialize>(val: T) -> Self {
|
||||
Self(serde_json::to_vec_pretty(&val))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoResponse for ErasedJson {
|
||||
|
||||
Reference in New Issue
Block a user