ktsu.ToStringJsonConverter 1.0.11

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package ktsu.ToStringJsonConverter --version 1.0.11                
NuGet\Install-Package ktsu.ToStringJsonConverter -Version 1.0.11                
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="ktsu.ToStringJsonConverter" Version="1.0.11" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ktsu.ToStringJsonConverter --version 1.0.11                
#r "nuget: ktsu.ToStringJsonConverter, 1.0.11"                
#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 ktsu.ToStringJsonConverter as a Cake Addin
#addin nuget:?package=ktsu.ToStringJsonConverter&version=1.0.11

// Install ktsu.ToStringJsonConverter as a Cake Tool
#tool nuget:?package=ktsu.ToStringJsonConverter&version=1.0.11                

ktsu.io.ToStringJsonConverter

Overview

ToStringJsonConverter is a JSON converter factory that simplifies serialization and deserialization of custom types in .NET by leveraging the ToString and FromString methods.

Features

  • Automatically identifies types with a FromString method for custom serialization.
  • Converts objects to and from JSON using their string representation.
  • Supports custom types with static FromString methods.

Installation

Install via NuGet:

dotnet add package ktsu.io.ToStringJsonConverter

Usage

Configure the converter in your JsonSerializerOptions:

var options = new JsonSerializerOptions();
options.Converters.Add(new ToStringJsonConverterFactory());

Example

public class MyType
{
    public string Value { get; set; }
    public static MyType FromString(string value) => new() { Value = value };
    public override string ToString() => Value;
}

var myType = new MyType { Value = "example" };
string json = JsonSerializer.Serialize(myType, options); // "example"
MyType deserialized = JsonSerializer.Deserialize<MyType>(json, options);

License

This project is licensed under the MIT License. See the LICENSE file for more details.

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 is compatible.  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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ktsu.ToStringJsonConverter:

Package Downloads
ktsu.AppDataStorage

Application data management library using JSON serialization to save and load data in the user's app data folder.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.22 74 11/27/2024
1.0.21 98 11/26/2024
1.0.20 132 11/20/2024
1.0.19 270 11/15/2024
1.0.18 146 11/14/2024
1.0.17 118 11/13/2024
1.0.16 382 11/4/2024
1.0.15 135 11/1/2024
1.0.14 563 10/17/2024
1.0.13 366 10/7/2024
1.0.12 124 10/4/2024
1.0.11 291 9/23/2024
1.0.10 115 9/20/2024
1.0.9 128 9/19/2024
1.0.8 129 9/19/2024
1.0.7 77 9/19/2024
1.0.6 115 9/19/2024
1.0.5 89 9/18/2024
1.0.4 88 9/18/2024
1.0.3 206 9/18/2024
1.0.2 131 9/18/2024
1.0.1 199 9/14/2024
1.0.0 99 9/14/2024