Description
To represent optional fields, we use unions in our schema. See the example below.
{
"type" : "record",
"name" : "Contact",
"fields" : [
,
,
,
,
{"name" : "Id","type" : [null, "long" ]} ]
}
In this schema PhoneNum, MiddleName and Id fields are declared as unions as they are optional fields. For this schema, Avrogencpp generates Contact structure and 3 separate union structures for each of the optional fields in the schema.
struct Contact
{
String FirstName;
String LastName;
Union_0 MiddleName;
Union_1 PhoneNum;
Union_3 Id;
}
Instead is it possible to create a new template based NullableType to represent optional fields. Basically if the schema has union with 2 fields and first field is null, it should generate Nullable type.
For the above scheme, it should generate something like this.
struct Contact
{
String FirstName;
String LastName;
Nullable<string> MiddleName;
Nullable<string> PhoneNum;
Nullable< long > Id;
}
This will reduce the number of generated unions in generated code and improve the readability and usability of the code.
Let me know if it's feasible to implement this.
Thanks,
Ramana