Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard 0.7.3

Prefix Reserved
dotnet add package Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard --version 0.7.3
                    
NuGet\Install-Package Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard -Version 0.7.3
                    
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="Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard" Version="0.7.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard" Version="0.7.3" />
                    
Directory.Packages.props
<PackageReference Include="Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard --version 0.7.3
                    
#r "nuget: Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard, 0.7.3"
                    
#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.
#:package Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard@0.7.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard&version=0.7.3
                    
Install as a Cake Addin
#tool nuget:?package=Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard&version=0.7.3
                    
Install as a Cake Tool

Build Status NuGet MyGet feedz.io

Aviationexam.GeneratedJsonConverters.SourceGenerator

Motivation for this library are polymorphic contracts with discriminator property not present as first property.

i.e. this JSON

{
    "baseProperty": 1,
    "$type": 2,
    "anotherLeafProperty": 2
}

is deserialized correctly into AnotherLeafContract using this library.

And string based enum serialization.

Install

<ItemGroup>
    <PackageReference Include="Aviationexam.GeneratedJsonConverters.SourceGenerator" Version="0.1.0" />
</ItemGroup>

The generated converters derive from public types in Aviationexam.GeneratedJsonConverters.Abstractions, which the generator package brings in as a dependency. netstandard2.0 projects get Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard instead, built from the same sources under a different assembly name. Do not mark the reference PrivateAssets="all": projects referencing yours need the abstractions assembly at runtime. The analyzer and its build properties stay private by default.

A netstandard2.0-only library used by net8.0+ applications must reference the netstandard2.0 abstractions itself, because those applications restore the generator for net8.0 and get only Aviationexam.GeneratedJsonConverters.Abstractions. The reference reaches them as a runtime-only dependency, so they never compile against both assemblies. A library that also targets net8.0 (for example netstandard2.0;net8.0) does not need it.

<ItemGroup>
    <PackageReference Include="Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard" Version="0.1.0" PrivateAssets="compile;contentfiles;analyzers;build" />
</ItemGroup>

How to use library

<PropertyGroup>
    
    <AVI_EJC_DefaultJsonSerializerContext_ClassAccessibility>public</AVI_EJC_DefaultJsonSerializerContext_ClassAccessibility>
    <AVI_EJC_DefaultJsonSerializerContext_Namespace>NamespaceOf.My.Json.Serializer.Context</AVI_EJC_DefaultJsonSerializerContext_Namespace>
    <AVI_EJC_DefaultJsonSerializerContext_ClassName>MyJsonSerializerContext</AVI_EJC_DefaultJsonSerializerContext_ClassName>

    
    <AVI_EJC_DefaultEnumSerializationStrategy>BackingType</AVI_EJC_DefaultEnumSerializationStrategy>

    
    <AVI_EJC_DefaultEnumDeserializationStrategy>UseBackingType|UseEnumName</AVI_EJC_DefaultEnumDeserializationStrategy>
</PropertyGroup>
// file=contracts.cs
using Aviationexam.GeneratedJsonConverters.Attributes;

[JsonPolymorphic] // notice, that attributes are from `Aviationexam.GeneratedJsonConverters.Attributes` namespace, not `System.Text.Json.Serialization`
[JsonDerivedType(typeof(LeafContract), typeDiscriminator: nameof(LeafContract))]
[JsonDerivedType(typeof(AnotherLeafContract), typeDiscriminator: 2)]
[JsonDerivedType<GenericLeafContract>(typeDiscriminator: nameof(GenericLeafContract))]
public abstract class BaseContract
{
    public int BaseProperty { get; set; }
}
public sealed class LeafContract : BaseContract
{
    public int LeafProperty { get; set; }
}
public sealed class AnotherLeafContract : BaseContract
{
    public int AnotherLeafProperty { get; set; }
}
public sealed class GenericLeafContract : BaseContract
{
    public int Property { get; set; }
}

[EnumJsonConverter] // this use project defined configuration
public enum EMyEnum
{
    [EnumMember(Value = "C")]
    A,
    [EnumMember(Value = "D")]
    B,
}

[EnumJsonConverter(
    SerializationStrategy = EnumSerializationStrategy.FirstEnumName,
    DeserializationStrategy = EnumDeserializationStrategy.UseEnumName
)]
public enum EMyEnumWithExplicitConfiguration
{
    [EnumMember(Value = "C")]
    A,
    [EnumMember(Value = "D")]
    B,
}

[DisableEnumJsonConverter]
public enum EMyIgnoredEnum
{
    C,
    D,
}

// file=MyJsonSerializerContext.cs
using System.Text.Json.Serialization;

[JsonSerializable(typeof(BaseContract))] // this line is neccesary, generator searches for JsonSerializableAttribute with argument type decorated by JsonPolymorphicAttribute
[JsonSerializable(typeof(LeafContract))] // notice, it's necessary to specify leaf types
[JsonSerializable(typeof(AnotherLeafContract))]
[JsonSerializable(typeof(GenericLeafContract))]

[JsonSerializable(typeof(EMyEnum))] // only necessary for not referenced enums from other contracts
[JsonSerializable(typeof(EMyEnumWithExplicitConfiguration))]
public partial class MyJsonSerializerContext : JsonSerializerContext
{
    static MyJsonSerializerContext()
    {
        // register generated converters to options
        UsePolymorphicConverters(s_defaultOptions.Converters);
        UseEnumConverters(s_defaultOptions.Converters);

        Default = new MyJsonSerializerContext(new System.Text.Json.JsonSerializerOptions(s_defaultOptions));
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Aviationexam.GeneratedJsonConverters.Abstractions.NetStandard:

Package Downloads
Aviationexam.GeneratedJsonConverters.SourceGenerator

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.7.3 111 10/16/2026
0.7.2 102 10/16/2026
0.7.1 109 10/15/2026
0.7.0 87 10/15/2026