mirror of https://github.com/tokio-rs/axum
Add support for returning pretty JSON response in `axum_extra::response::ErasedJson` (#662)
This commit is contained in:
parent
4fd7e927ba
commit
d602682821
|
@ -14,8 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
# 0.1.1 (27. December, 2021)
|
||||
|
||||
- Add `middleware::from_fn` for creating middleware from async functions ([#656])
|
||||
- Add support for returning pretty JSON response in `response::ErasedJson` ([#662])
|
||||
|
||||
[#656]: https://github.com/tokio-rs/axum/pull/656
|
||||
[#662]: https://github.com/tokio-rs/axum/pull/662
|
||||
|
||||
# 0.1.0 (02. December, 2021)
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue