dropbox / dropbox-sdk-rust

Dropbox SDK for Rust
Apache License 2.0
77 stars 18 forks source link

Skip serializing struct fields whose values are `None` #61

Closed wfraser closed 3 years ago

wfraser commented 3 years ago

This changes how structs with optional fields are serialized. Previously, fields whose value was set to None were serialized in the JSON as null. This works, but is unnecessarily verbose, but the bigger deal is that it isn't accepted by our deserializer code.

With this change, we skip writing these fields entirely.

Now, we could fix the deserializers to accept null for Option fields, but for now let's just stop using null entirely. We can always add that support later if there's a good reason to.

This also beefs up the tests by adding test cases for structs which omit all the optional fields, which is how I verified this works correctly. These tests will also be good for catching compatibility issues in the future.

Checklist

General Contributing

Validation

test change included