Open seime opened 3 years ago
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