salesforce / grpc-java-contrib

Useful extensions for the grpc-java library
BSD 3-Clause "New" or "Revised" License
218 stars 34 forks source link

Proto enum map support #240

Closed 313hemant313 closed 10 months ago

313hemant313 commented 1 year ago

Wanted to check if anyone has tried some modification to generated java classes to add Enum key support in proto map.

rmichela commented 1 year ago

Can you elaborate on this? I'm not sure I understand your use case.

313hemant313 commented 1 year ago

In proto Enums as Map Keys support is not available. https://github.com/protocolbuffers/protobuf/issues/7791

Wanted to check if somehow we can add some extra code to make this happen.

rmichela commented 1 year ago

That linked issue did a pretty good job of explaining why enum map keys were not implemented in protobuf core.

How would you propose dealing with a map of enum keys in Java, when the client can send keys that are not understood by the server?

In theory, you could build a code generator with jProtoc to emit Java helper classes for working with maps keyed by integers that correspond to enums, but you would have to place difficult constraints on contract evolution.

313hemant313 commented 1 year ago

I was thinking to create a Any type field in proto and will disable getters and setters. Using jProtoc will add Any to EnumMap getter and setters.

For keys that are not understood will be mapped to maybe NOT_SUPPORTED enum value.

313hemant313 commented 1 year ago

@rmichela Do you think if above will be possible with jProtoc ?

rmichela commented 1 year ago

I don't believe so. JProtoc can or change the behavior of the default proto compiler.

313hemant313 commented 11 months ago

Can any one please help with sample code to make a proto generated class implement any interface ?