-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enum mapping from protobuf class to protobuf class is wrong #136
Comments
This is AFAIK technically un-fixable, because the SPI interface does not communicate the mapping target type, so one cannot distinguish between mapping a Protobuf enum to a Java enum (in which case there is no UNRECOGNIZED, so mapping UNSPECIFIED and UNRECOGNIZED both to null is the correct thing to do) and mapping to another Protobuf enum, where there is an UNRECOGNIZED type on both sides and thus mapping UNRECOGNIZED to null (which is what causes UNSPECIFIED to be mapped to UNRECOGNIZED) is counterproductive. I have implemented some kind of work-around in another mapstruct-protobuf SPI implementation I'm maintaining over here: https://github.com/S1artie/mapstruct-spi-protobuf - this solution uses a new feature of Mapstruct 1.6, custom configuration values, to allow the user to control whether UNRECOGNIZED is mapped to null. By default it's done, but when generating protobuf-to-protobuf mapping code, it can be deactivated (because in that case you can rely on there being the UNRECOGNIZED magic value to be present in the target enum) and thus the mapping of _UNSPECIFIED is fixed. |
Default 0 constant (_UNSPECIFIED) maps to UNRECOGNIZED in generated code.
See branch proto_to_proto_mapping
The text was updated successfully, but these errors were encountered: