Fix union type naming in FastSerializerGenerator#600
Open
jcastagno wants to merge 1 commit intolinkedin:masterfrom
Open
Fix union type naming in FastSerializerGenerator#600jcastagno wants to merge 1 commit intolinkedin:masterfrom
jcastagno wants to merge 1 commit intolinkedin:masterfrom
Conversation
When generating serializers for arrays or maps containing union types, the code was calling schema.getName() which doesn't work for unions (they don't have names). This caused invalid Java variable names like 'UNION0' to be generated, leading to compilation failures. Changes: - Enhanced SchemaAssistant.getTypeName() to handle UNION types by concatenating branch type names (e.g., 'union_NULL_STRING') - Updated FastSerializerGenerator to use getTypeName() instead of getName() when declaring variables for array elements and map values - Added 5 comprehensive tests covering nullable and multi-type unions in arrays, maps, and records The fix generates valid Java identifiers like: - union_NULL_STRING0 (instead of UNION0) - union_INT_STRING_DOUBLE0 (for multi-type unions) - union_NULL_record0 (for nullable record unions)
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.
Problem
When generating serializers for arrays or maps containing union types, the code was calling
schema.getName()which doesn't work for unions (they don't have names). This caused invalid Java variable names likeUNION0to be generated, leading to compilation failures.Solution
SchemaAssistant.getTypeName()to handle UNION types by concatenating branch type names (e.g.,union_NULL_STRING).FastSerializerGeneratorto usegetTypeName()instead ofgetName()when declaring variables for array elements and map values.Examples of Generated Names
union_NULL_STRING0(instead ofUNION0)union_INT_STRING_DOUBLE0(for multi-type unions)union_NULL_record0(for nullable record unions)Files Changed
FastSerializerGenerator.java- Fixed two locations where union schemas needed proper namingSchemaAssistant.java- Added UNION case togetTypeName()methodFastGenericSerializerGeneratorTest.java- Added 5 new test casesTesting
All existing tests pass, plus 5 new tests validate: