Skip to content

Add IPolymorphicJsonConvertor interface and JsonSourceGenerationMode.Metadata support#338

Merged
trejjam merged 22 commits intomainfrom
feature/get-type-resolvers
Mar 13, 2026
Merged

Add IPolymorphicJsonConvertor interface and JsonSourceGenerationMode.Metadata support#338
trejjam merged 22 commits intomainfrom
feature/get-type-resolvers

Conversation

@trejjam
Copy link
Member

@trejjam trejjam commented Mar 13, 2026

Summary

  • Introduce IPolymorphicJsonConvertor<T> interface with static abstract members (NET7+) enabling compile-time polymorphic dispatch via CRTP pattern (PolymorphicJsonConvertor<TConverter, T>)
  • Generate ConfigureJsonTypeInfo on each polymorphic converter to inject discriminator properties into JsonTypeInfo, enabling JsonSourceGenerationMode.Metadata serialization
  • Generate GetPolymorphicJsonTypeInfoConfigurations() / GetEnumJsonTypeInfoConfigurations() on serializer contexts, giving consumers a clean API to register type info modifiers
  • Update PolymorphicJsonConvertor.Write to detect when discriminator is already present in type info properties (metadata mode) and delegate directly to JsonSerializer.Serialize instead of manual property writing
  • Add netstandard2.0 target to the Target project with PolySharp and System.Text.Json dependencies
  • Rename instance methods to Self_ prefix as NET<7 fallback bridge to the new static abstract interface
  • Add new serialization tests (SerializeLeafContractWorks, SerializeAnotherLeafContractWorks, SerializeLeafContractWithCustomDelimiterWorks) and a JsonSourceGenerationMode.Metadata snapshot test
  • Regenerate all snapshot tests to reflect the updated generated code shape

@trejjam trejjam added this pull request to the merge queue Mar 13, 2026
Merged via the queue into main with commit 4cefdf0 Mar 13, 2026
2 checks passed
@trejjam trejjam deleted the feature/get-type-resolvers branch March 13, 2026 23:48
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