serde_with
serde_with copied to clipboard
This crate provides custom de/serialization helpers to use in combination with serde's `with`-annotation and with the improved `serde_as`-annotation.
In my attempt to update to `[email protected]` I noticed that nested JSON support is gone, with a changelog stating that: > `json::nested` can be replaced with `#[serde_as(as = "json::JsonString")]`. It...
https://github.com/rust-lang/rust/blob/afaf33dcafe9c7068b63eb997df221aa08db7c29/library/core/src/array/mod.rs#L563-L628 This is not a public function, so the code needs to be copied. This is very likely be better than the existing code. The function uses too many unstable...
Serde natively supports `NonZeroT` already, but this converter could support lossless serialization and deserialization.
Serialization code is often repetitive. One helper to improve on this already exists in this crate, the [`serde_with::skip_serializing_none`](https://docs.rs/serde_with/1.4.0/serde_with/attr.skip_serializing_none.html) attribute. However, this could be generalized to work with any attribute on...
Sometimes structs/enums need an additional root element. This can be done with a single element enum like so: ```rust #[derive(Serialize)] enum Foobar { #[serde(rename = "root_field_name")] RootName{ field_a: bool, field_b:...
Sometimes it makes sense to deserialize a map as a list of single items, i.e., `Vec`. The map-key becomes a special field in `T`. ```json { "id0": { "field_a": ...,...
Perhaps not such a common use case as stripping prefixes, but it would be nice if there was a symmetrical `with_suffix` macro that could strip suffixes.
This is one way to e.g. successfully roundtrip things like `Option` into formats that have `unwrap_or_null` behavior by default (as opposed to e.g. `double_option` or `unwrap_or_skip`). Example implementation: ```rust use...
Example: ```rust use serde::Serialize; use serde_with::skip_serializing_none; #[skip_serializing_none] #[derive(Serialize)] struct Person
As seen in #201 it might be confusing why this code doesn't work: ```rust // Can't get this working at all #[serde_as(as = "BTreeMap")] pub map: BTreeMap, // Confusingly enough...