Allow optional attributes field
Closed this issue ยท 2 comments
xiao-e-yun commented
Some API will filter values is null of key.
Can you add an feature to handle field not includes in attributes.
Like #[json_api(optional)] or #[json_api(default)].
Very thanks!
DASPRiD commented
I think default makes a lot of sense, that would also somewhat mirror how serde handles these. I definitely do not want to treat any Option<T> as optional, as there needs to be a distinct difference between undefined and null, and Option<T> already handles null.
This should handle both attributes and fields. Actually I think we should supply two ways to handle this.
#[json_api(default)]โ works exactly like#[serde(default)], so would, with anOption<T>, set it toNoneif missing, which is not distinguishable fromnullthough.#[json_api(optional)]โ would require a wrapper around the final type. This is a little bit tricky. In the classic serde way, we could require anOption<U>around the actual type, which in case of nullable types, would result inOption<Option<T>>. This would be the most idiomatic way, and the most easy to implement.
github-actions commented
๐ This issue has been resolved in version 1.3.0 ๐
The release is available on:
v1.3.0- GitHub release
Your semantic-release bot ๐ฆ๐