PolymorphicJsonTypeInfoResolver 0.1.8
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package PolymorphicJsonTypeInfoResolver --version 0.1.8
NuGet\Install-Package PolymorphicJsonTypeInfoResolver -Version 0.1.8
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.1.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PolymorphicJsonTypeInfoResolver --version 0.1.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PolymorphicJsonTypeInfoResolver, 0.1.8"
#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.1.8 // Install PolymorphicJsonTypeInfoResolver as a Cake Tool #tool nuget:?package=PolymorphicJsonTypeInfoResolver&version=0.1.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Polymorphic Json Type Info Resolver
Using polymorphism with the contract model available since .NET7+
.
var options = new JsonSerializerOptions {
TypeInfoResolver = new PolymorphicTypeInfoResolver()
.Type<B>(x => x.DerivedTypes.Add<C>("c"))
}
var json = JsonSerializer.Serialize(new A(new C("cheap")), options);
{
"Specification": {
"$type":"C",
"Remarks":"cheap"
}
}
Factory for default options:
var options = new JsonSerializerOptions {
TypeInfoResolver = new PolymorphicTypeInfoResolver(options: () => new JsonPolymorphismOptions {
TypeDiscriminatorPropertyName = "$TYPE"
})
};
Opt-in for all derived types (from the same assemby):
new JsonSerializerOptions {
TypeInfoResolver = new PolymorphicTypeInfoResolver()
.Type<C>(x => x
.DerivedTypes
.AddAllAssignableTo<C>())
};
Product | Versions 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 | 2,387 | 6/7/2024 |
7.1.0-alpha.1 | 109 | 4/24/2023 |
7.0.16 | 1,703 | 4/24/2023 |
7.0.15 | 237 | 4/24/2023 |
0.1.14 | 203 | 4/24/2023 |
0.1.13 | 181 | 4/24/2023 |
0.1.12 | 189 | 4/24/2023 |
0.1.11 | 192 | 4/22/2023 |
0.1.10 | 182 | 4/21/2023 |
0.1.9 | 217 | 4/21/2023 |
0.1.8 | 179 | 4/21/2023 |
0.0.7 | 206 | 4/20/2023 |
0.0.6 | 198 | 4/20/2023 |
0.0.4 | 196 | 4/20/2023 |
0.0.3 | 201 | 4/20/2023 |
0.0.1 | 201 | 4/20/2023 |
Breaking change: using `JsonPolymorphismOptions` instead of wrapping in own builder.