Skip to content

Conversation

@trejjam
Copy link
Member

@trejjam trejjam commented Jan 5, 2026

Summary

This PR adds support for generating polymorphic JSON converters when multiple JsonSerializerContext classes reference the same polymorphic types. The generator now properly merges configurations across multiple contexts and generates converters for each namespace.

Key Changes

Core Functionality

  • Multiple Context Support: The generator can now handle multiple JsonSerializerContext classes that reference the same polymorphic types
  • Context Merging: Introduced PolymorphicJsonSerializerContextConfigurationMerger to merge configurations from multiple contexts
  • Metadata Structure: Added PolymorphicJsonSerializerMetadata to separate metadata concerns from configuration

Code Quality Improvements

  • Refactored Generator Logic: Extracted lambda expressions into named methods for better readability
  • Replaced LINQ with ZLinq: Improved performance by using ZLinq throughout
  • Improved Namespace Handling: Better support for multiple namespaces and global namespace

Testing Enhancements

  • New Test: MultipleContextsWorks validates generation with multiple JsonSerializerContext classes
  • Integration Tests: Added tests for MySecondJsonSerializerContext and nullable leaf contracts with custom delimiters
  • Snapshot Updates: Updated all snapshot tests to reflect the new generator output

Technical Details

  • Changed from single context (ISymbol) to multiple contexts (EquatableArray<ISymbol>)
  • Converters are now grouped by target namespace
  • Generator produces separate partial class extensions for each JsonSerializerContext
  • Added support for .NET 10 via NET_10_OR_GREATER conditional compilation

Testing

All existing tests pass. New tests added:

  • JsonPolymorphicConverterGeneratorSnapshotTests.MultipleContextsWorks
  • BaseContractWithCustomDelimiterSerializationTests with multiple contexts
  • Integration tests for nullable leaf contracts

Breaking Changes

None - this is backward compatible. Existing single-context scenarios continue to work as before.

trejjam added 30 commits January 5, 2026 15:45
@trejjam trejjam added this pull request to the merge queue Jan 5, 2026
Merged via the queue into main with commit f92ffb2 Jan 5, 2026
2 checks passed
@trejjam trejjam deleted the feature/support-multiple-contexts branch January 5, 2026 21:19
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.

2 participants