Skip to content

Fix union type naming in FastSerializerGenerator#600

Open
jcastagno wants to merge 1 commit intolinkedin:masterfrom
jcastagno:fix/union-type-naming-in-arrays-maps
Open

Fix union type naming in FastSerializerGenerator#600
jcastagno wants to merge 1 commit intolinkedin:masterfrom
jcastagno:fix/union-type-naming-in-arrays-maps

Conversation

@jcastagno
Copy link

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 like UNION0 to be generated, leading to compilation failures.

Solution

  • 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.

Examples of Generated Names

  • union_NULL_STRING0 (instead of UNION0)
  • 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 naming
  • SchemaAssistant.java - Added UNION case to getTypeName() method
  • FastGenericSerializerGeneratorTest.java - Added 5 new test cases
  • Generated test files - Show the corrected naming in action

Testing

All existing tests pass, plus 5 new tests validate:

  • Arrays of nullable unions
  • Maps of nullable unions
  • Records containing union arrays
  • Arrays of multi-type unions
  • Maps of multi-type unions

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)
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

Successfully merging this pull request may close these issues.

1 participant