You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Protobuf, when using the OneOf construct, generates an enum and a <Field>OneOfCase property, which contains one of the values indicating which of the body fields is filled. This information can be used when generating the mapper with inheritance.
I realize this may seem like a "niche" situation, but gRPC and Protobuf usage is pretty widespread, so OneOf inheritance support would be a nice addition.
The text was updated successfully, but these errors were encountered:
Thanks for raising this point! A more protobuf-independent approach could indeed be achieved using a type discriminator for mapping derived types. This would align with how System.Text.Json handles polymorphism (see docs).
For example, the Mapperly API could look like this:
This design would not only support protobuf, but could also work seamlessly with other type discriminators, making the feature more versatile and broadly applicable.
What do you think about this approach?
latonz
changed the title
Protobuf OneOf support
Derived types: Type descriminator support
Jan 6, 2025
Protobuf, when using the OneOf construct, generates an enum and a
<Field>OneOfCase
property, which contains one of the values indicating which of the body fields is filled. This information can be used when generating the mapper with inheritance.Proto:
Generated class (simplified):
Mapper config:
Generated mapper:
I realize this may seem like a "niche" situation, but gRPC and Protobuf usage is pretty widespread, so OneOf inheritance support would be a nice addition.
The text was updated successfully, but these errors were encountered: