ktsu.ToStringJsonConverter 1.0.21

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.21                
NuGet\Install-Package ktsu.ToStringJsonConverter -Version 1.0.21                
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.21" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ktsu.ToStringJsonConverter --version 1.0.21                
#r "nuget: ktsu.ToStringJsonConverter, 1.0.21"                
#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.21

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

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.26 3 12/1/2024
1.0.25 25 12/1/2024
1.0.24 59 11/30/2024
1.0.23 39 11/29/2024
1.0.22 114 11/27/2024
1.0.21 122 11/26/2024
1.0.20 137 11/20/2024
1.0.19 274 11/15/2024
1.0.18 150 11/14/2024
1.0.17 122 11/13/2024
1.0.16 386 11/4/2024
1.0.15 139 11/1/2024
1.0.14 565 10/17/2024
1.0.13 368 10/7/2024
1.0.12 126 10/4/2024
1.0.11 293 9/23/2024
1.0.10 117 9/20/2024
1.0.9 130 9/19/2024
1.0.8 131 9/19/2024
1.0.7 79 9/19/2024
1.0.6 117 9/19/2024
1.0.5 91 9/18/2024
1.0.4 90 9/18/2024
1.0.3 208 9/18/2024
1.0.2 133 9/18/2024
1.0.1 201 9/14/2024
1.0.0 101 9/14/2024