PolymorphicJsonTypeInfoResolver 0.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package PolymorphicJsonTypeInfoResolver --version 0.0.6                
NuGet\Install-Package PolymorphicJsonTypeInfoResolver -Version 0.0.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PolymorphicJsonTypeInfoResolver" Version="0.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PolymorphicJsonTypeInfoResolver --version 0.0.6                
#r "nuget: PolymorphicJsonTypeInfoResolver, 0.0.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PolymorphicJsonTypeInfoResolver as a Cake Addin
#addin nuget:?package=PolymorphicJsonTypeInfoResolver&version=0.0.6

// Install PolymorphicJsonTypeInfoResolver as a Cake Tool
#tool nuget:?package=PolymorphicJsonTypeInfoResolver&version=0.0.6                

Polymorphic Json Type Info Resolver

nuget stryker

Using polymorphism with the contract model available since .NET7+.

var resolver = new PolymorphicTypeInfoResolver()
    .Type<B>(x => x
        .Has<C>()
        .Has<D>("d"));
        
var json = JsonSerializer.Serialize(new A(new C("cheap")), new JsonSerializerOptions {
    TypeInfoResolver = resolver
});
{
    "Specification": {
        "$type":"C",
        "Remarks":"cheap"
    }
}
var data = JsonSerializer.Deserialize<A>(json, new JsonSerializerOptions {
    TypeInfoResolver = resolver
});

Api inspired by EF model inheritance.

new PolymorphicTypeInfoResolver()
    .Type<B>(x => x
        .Discriminator("$TYPE")
        .Has<C>()
        .Has<D>());

Opt-in for all derived types (from the same assemby):

new PolymorphicTypeInfoResolver()
    .Type<C>(x => x.AddAllDerived())
    .Type<D>(x => x.AddAllDerived(t => t.Name.ToLowerInvariant()));
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.27 1,594 6/7/2024
7.1.0-alpha.1 106 4/24/2023
7.0.16 1,698 4/24/2023
7.0.15 232 4/24/2023
0.1.14 198 4/24/2023
0.1.13 176 4/24/2023
0.1.12 184 4/24/2023
0.1.11 187 4/22/2023
0.1.10 177 4/21/2023
0.1.9 212 4/21/2023
0.1.8 174 4/21/2023
0.0.7 201 4/20/2023
0.0.6 191 4/20/2023
0.0.4 191 4/20/2023
0.0.3 196 4/20/2023
0.0.1 194 4/20/2023

.