iddm / serde-aux

An auxiliary serde library providing helpful functions for serialisation and deserialisation for containers, struct fields and others.
MIT License
152 stars 26 forks source link

Add `deserialize_default_from_empty_object`. #5

Closed reitermarkus closed 5 years ago

reitermarkus commented 5 years ago

In addition to deserialize_default_from_null, this also treats empty objects ({}) as null.

Also, I fixed the deserialize_default_from_null. It would actually treat an Err as null because I accidentally simplified the code too much and moved the .unwrap_or from an Option to a Result.

reitermarkus commented 5 years ago

You mean undefined as in absent? I think you still have to add #[serde(default)] to handle absent fields.

iddm commented 5 years ago

You mean undefined as in absent? I think you still have to add #[serde(default)] to handle absent fields.

No no, I meant this:

{ "value": undefined }

Is this valid json? If it is, should we also treat undefined in the way we do null and {}?

According to jsonlint validator it is not a valid json, so I guess, the answer is no, we don't have to handle this as it is impossible to have it and, probably, it will not even be parsed by serde itself.

reitermarkus commented 5 years ago

Is this valid json?

No, JSON only supports null.

iddm commented 5 years ago

@reitermarkus Thank you!

reitermarkus commented 5 years ago

You're welcome!