feat: support unrecognized enum values#693
Merged
anthony-swirldslabs merged 1 commit intomainfrom Dec 11, 2025
Merged
Conversation
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
imalygin
approved these changes
Nov 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
Introducing support for unrecognized enum values.
UNRECOGNIZED(-1)enum constant addedenumField()returnsUNRECOGNIZEDfor unknown proto ordinalsint enumFieldProtoOrdinal()returns the protoOrdinal as parsed from inputList<Integer> enumListFieldProtoOrdinals()similar to the aboveThe implementation avoids increasing the memory footprint of generated protobuf models by replacing the real enum type with
Object/List<?>for the private fields that store these values. In other words, with this fix, Java models still maintain just a single reference field for each protobuf enum field - same as before. The Object can be either an actual enum constant or anIntegerrepresenting its unrecognized protoOrdinal value.Getters for repeated enum fields (both simple and
...ProtoOrdinals()) are penalized slightly because they have to construct new lists each time. As a future work, we could consider caching the results in runtime similar to how we do with the hashCode/length. However, this would increase the memory foot print for such models. For this reason, I haven't implemented this just yet. Note that non-repeated enum fields are unaffected by this at all and should work as fast as they do today.Related issue(s):
Fixes #476
Notes for reviewer:
A new integration test is added to verify the behavior.
Checklist