I managed to implement this using the union type which I didn't know
about until a couple of days ago.
Here is a snippet in case someone else had the same use case.
union NullableString {
1: bool isNull,
2: string value,
}
struct Account {
1: i64 id,
2: string username,
3: required string password,
4: optional NullableString name,
}
Using NullableString I can distinguish between missing and null strings:
if (account.getName() == null) {
// name field is not set
} else {
if (account.getName().getSetField() == NullableString._Fields.IS_NULL) {
// name field is set to NULL
} else {
// name is set to account.getName().getValue()
}
}
-Sid