Skip to content
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

Open
seime opened this issue Nov 8, 2021 · 1 comment
Open

Enum mapping from protobuf class to protobuf class is wrong #136

seime opened this issue Nov 8, 2021 · 1 comment

Comments

@seime
Copy link
Contributor

seime commented Nov 8, 2021

Default 0 constant (_UNSPECIFIED) maps to UNRECOGNIZED in generated code.

See branch proto_to_proto_mapping

@S1artie
Copy link

S1artie commented Aug 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants