axum-extra: Add trailing newline to pretty JSON response (#3526)

This commit is contained in:
Asger Hautop Drewsen
2025-11-24 21:34:46 +01:00
committed by GitHub
parent 9bd839e5e9
commit e668598cef
+4 -1
View File
@@ -57,7 +57,10 @@ impl ErasedJson {
pub fn pretty<T: Serialize>(val: T) -> Self {
let mut bytes = BytesMut::with_capacity(128);
let result = match serde_json::to_writer_pretty((&mut bytes).writer(), &val) {
Ok(()) => Ok(bytes.freeze()),
Ok(()) => {
bytes.put_u8(b'\n');
Ok(bytes.freeze())
}
Err(e) => Err(Arc::new(e)),
};
Self(result)