fix: toJSON Function with removeEnumPrefix=true
and unrecognizedEnumValue=0
Options
#1089
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.
close: #1086
This PR addresses the issue described in #1086, where the
toJSON
function generated by ts-proto incorrectly serializes enum values when both theremoveEnumPrefix=true
andunrecognizedEnumValue=0
options are used.The expected behavior is that, even with
removeEnumPrefix=true
, thetoJSON
function should encode the enum values using their original string values, including the prefix. However, the bug causes the function to encode the enum values without the prefix, leading to incorrect JSON serialization.To fix this, the PR updates the
toJSON
function to correctly use the original enum name, including the prefix, when encoding. This is achieved by storing theoriginalName
alongside theUnrecognizedEnum
value and using it during serialization.This change ensures that the enum values are correctly serialized with their full names, aligning the behavior with the expected output when these options are enabled.
If this code format doesn't align with the maintainer's preferences, please feel free to modify it as needed.