DASPRiD/jsonapi-deserialize-rs

Allow optional attributes field

Closed this issue ยท 2 comments

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!

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.

  1. #[json_api(default)] โ€“ works exactly like #[serde(default)], so would, with an Option<T>, set it to None if missing, which is not distinguishable from null though.
  2. #[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 an Option<U> around the actual type, which in case of nullable types, would result in Option<Option<T>>. This would be the most idiomatic way, and the most easy to implement.

๐ŸŽ‰ This issue has been resolved in version 1.3.0 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€