facebookarchive / swift

An annotation-based Java library for creating Thrift serializable types and services.
Apache License 2.0
900 stars 297 forks source link

Swift does not respect optional keyword, or default values for optionals #71

Closed andrewcox closed 6 years ago

andrewcox commented 11 years ago

In thrift IDL, the "optional" keyword applied to a struct field means that the writer will not serialize the optional value if it is not set, and the reader side will fill in the field with the default value declared in the IDL, or the default for the type if there was no declared default. The reader will have a way to tell if the writer set the field or not.

Currently, swift lets you set a field to null, and when that field is null, the writer will not write the value. The reader will see a null when reading the type. But this leaves a couple of very minor gaps:

Someday it might be nice to add an Optional type, that acts like guava Optional except that it has a "orDefault()" method that would return the set value or the default. The sender could then not send if isPresent()==false, and the receiver could use orDefault() to get the effective value, while using isPresent() to determine whether the value was received from the sender or not.

hgschmie commented 11 years ago

Does the IDL parser parse the optional keyword correctly?

andrewcox commented 11 years ago

Yes

ghost commented 9 years ago

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.