ktsu.io.ToStringJsonConverter
1.0.0
Prefix Reserved
dotnet add package ktsu.io.ToStringJsonConverter --version 1.0.0
NuGet\Install-Package ktsu.io.ToStringJsonConverter -Version 1.0.0
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.io.ToStringJsonConverter" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ktsu.io.ToStringJsonConverter --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ktsu.io.ToStringJsonConverter, 1.0.0"
#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.io.ToStringJsonConverter as a Cake Addin #addin nuget:?package=ktsu.io.ToStringJsonConverter&version=1.0.0 // Install ktsu.io.ToStringJsonConverter as a Cake Tool #tool nuget:?package=ktsu.io.ToStringJsonConverter&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | 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 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.
-
net7.0
- ktsu.io.Extensions (>= 1.0.0)
-
net8.0
- ktsu.io.Extensions (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ktsu.io.ToStringJsonConverter:
Package | Downloads |
---|---|
ktsu.io.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.0 | 1,473 | 6/19/2024 |
1.0.0-alpha.2 | 48 | 6/19/2024 |
1.0.0-alpha.1 | 49 | 6/19/2024 |