What is the best process for making a required
field optional
in thrift. For example, I have a struct...
struct Message {
1: required double userID;
2: required string content;
...
}
... but I want to make content
optional.
EDIT: To clarify, I already have consumers that use this struct, so I would need to update it without breaking those consumers. A staged upgrade is fine (ie - add a new optional
field, update the downstream clients, then remove--or stop using--the old required
field).
In some languages it's quite elegant and simple wherein we just append a question mark after the field name. There is no concept for this in Java. Most people would just assign null to it and return Optional<String> on methods that would return it.
Thrift structs define a common object – they are essentially equivalent to classes in OOP languages, but without inheritance. A struct has a set of strongly typed fields, each with a unique name identifier. Fields may have various annotations (numeric field IDs, optional default values, etc.)
It is possible to do this if you control all the readers and writers of the struct in the following steps :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With