Skip to content

Using NoneAsEmptyString causes missing values to trigger a DeserializeBodyError #517

Answered by jonasbb
mu-arch asked this question in Q&A
Discussion options

You must be logged in to vote

It is really helpful in understanding the problem, if you can provide a runnable example including the serialized form and the expected outcome.

This is expected behavior of the serde derives. If you use with or deserialize_with on a field, the field becomes mandatory. The as and deserialize_as boil down to with/deserialize_with, so the same applies here. You need to add #[serde(default)] if you want to make the field optional.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mu-arch
Comment options

Answer selected by jonasbb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants