StringTypeEnumConverter.Newtonsoft 1.1.4

dotnet add package StringTypeEnumConverter.Newtonsoft --version 1.1.4                
NuGet\Install-Package StringTypeEnumConverter.Newtonsoft -Version 1.1.4                
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="StringTypeEnumConverter.Newtonsoft" Version="1.1.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StringTypeEnumConverter.Newtonsoft --version 1.1.4                
#r "nuget: StringTypeEnumConverter.Newtonsoft, 1.1.4"                
#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 StringTypeEnumConverter.Newtonsoft as a Cake Addin
#addin nuget:?package=StringTypeEnumConverter.Newtonsoft&version=1.1.4

// Install StringTypeEnumConverter.Newtonsoft as a Cake Tool
#tool nuget:?package=StringTypeEnumConverter.Newtonsoft&version=1.1.4                

StringTypeEnumConverter

A more precise enum converter for Newtonsoft json.

When serializing and deserializing an Enum using Newtonsoft.Json, you may get the problem of knowing what was the specific enum type.<br> This may happen if your class declares a property of type Enum, instead of the specific enum.

The problem:
        public class TestClass
        {
            public Enum Enum1 { get; set; }
        }

The "Enum1" field is declared as Enum.<br>This allows it to be filled with any enum. If you try to fill it with StringComparison enum, using the value OrdinalIgnoreCase, the serialized output, will be:

        {"Enum1":5}

The result cannot be acceptable for common uses, because you actually don't know what enum was used. The serialization lost the information.

The solution:

This enum converter aims to solve this problem, by extending the out-of-the-box converter "StringEnumConverter", that writes the string value instead of its underlying type (int in this case).<br> The class we are extending only writes the string value of the enum:

        {"Enum1":"OrdinalIgnoreCase"}

StringTypeEnumConverter extends this concept, writing the string value along with the originating enum type name, in this way:

        {"Enum1":"StringComparison.OrdinalIgnoreCase"}

When deserializing, it looks for the StringComparison enum type in a given array of assemblies, and returns that type.

For code and more info: https://github.com/jonnidip/StringTypeEnumConverter

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
.NET Core netcoreapp3.0 is compatible.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 is compatible.  net461 is compatible.  net462 is compatible.  net463 was computed.  net47 is compatible.  net471 is compatible.  net472 is compatible.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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

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
1.1.4 4,116 5/20/2021
1.1.3 446 11/18/2020
1.1.2.2 383 10/23/2020
1.1.2.1 429 10/14/2020
1.1.2 435 10/6/2020
1.1.1-beta 281 10/6/2020
1.1.0-beta 297 10/5/2020
1.0.1 451 10/3/2020