PosInformatique.Foundations.EmailAddresses.Json 1.0.0-alpha.4

Prefix Reserved
This is a prerelease version of PosInformatique.Foundations.EmailAddresses.Json.
dotnet add package PosInformatique.Foundations.EmailAddresses.Json --version 1.0.0-alpha.4
                    
NuGet\Install-Package PosInformatique.Foundations.EmailAddresses.Json -Version 1.0.0-alpha.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="PosInformatique.Foundations.EmailAddresses.Json" Version="1.0.0-alpha.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PosInformatique.Foundations.EmailAddresses.Json" Version="1.0.0-alpha.4" />
                    
Directory.Packages.props
<PackageReference Include="PosInformatique.Foundations.EmailAddresses.Json" />
                    
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 PosInformatique.Foundations.EmailAddresses.Json --version 1.0.0-alpha.4
                    
#r "nuget: PosInformatique.Foundations.EmailAddresses.Json, 1.0.0-alpha.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.
#:package PosInformatique.Foundations.EmailAddresses.Json@1.0.0-alpha.4
                    
#: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=PosInformatique.Foundations.EmailAddresses.Json&version=1.0.0-alpha.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=PosInformatique.Foundations.EmailAddresses.Json&version=1.0.0-alpha.4&prerelease
                    
Install as a Cake Tool

PosInformatique.Foundations.EmailAddresses.Json

NuGet version NuGet downloads

Introduction

Provides a System.Text.Json converter for the EmailAddress value object from PosInformatique.Foundations.EmailAddresses. Enables seamless serialization and deserialization of RFC 5322 compliant email addresses within JSON documents.

Install

You can install the package from NuGet:

dotnet add package PosInformatique.Foundations.EmailAddresses.Json

This package depends on the base package PosInformatique.Foundations.EmailAddresses.

Features

  • Provides a JsonConverter<EmailAddress> for serialization and deserialization.
  • Ensures validation of RFC 5322 compliant email addresses when deserializing.
  • Can be used via attributes ([JsonConverter]) or through JsonSerializerOptions extension method.
  • Ensures consistency with the base EmailAddress value object.

Use cases

  • Serialization: Convert value objects into JSON strings without losing semantics
  • Validation: Guarantee that only valid RFC 5322 email addresses are accepted in JSON payloads
  • Integration: Plug directly into System.Text.Json configuration

Examples

Example 1: DTO with [JsonConverter] attribute

using System.Text.Json;
using System.Text.Json.Serialization;
using PosInformatique.Foundations;

public class UserDto
{
    [JsonConverter(typeof(EmailAddressJsonConverter))]
    public EmailAddress Email { get; set; } = default!;
}

// Serialization
var dto = new UserDto { Email = "john.doe@example.com" };
var json = JsonSerializer.Serialize(dto);
// Result: {"Email":"john.doe@example.com"}

// Deserialization
var input = "{ "Email": "alice@company.org" }";
var deserialized = JsonSerializer.Deserialize<UserDto>(input);
Console.WriteLine(deserialized!.Email); // "alice@company.org"

Example 2: Use extension method without attributes

using System.Text.Json;
using PosInformatique.Foundations;

public class CustomerDto
{
    public EmailAddress Email { get; set; } = default!;
}

var options = new JsonSerializerOptions().AddEmailAddressesConverters();

// Serialization
var dto = new CustomerDto { Email = "bob@myapp.com" };
var json = JsonSerializer.Serialize(dto, options);
// Result: {"Email":"bob@myapp.com"}

// Deserialization
var input = "{ "Email": "carol@myapp.com" }";
var deserialized = JsonSerializer.Deserialize<CustomerDto>(input, options);
Console.WriteLine(deserialized!.Email); // "carol@myapp.com"
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
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.0.0-alpha.4 33 9/27/2025
1.0.0-alpha.3 63 9/26/2025
1.0.0-alpha.2 71 9/26/2025

1.0.0
 - Initial release with the support JSON serialization (with System.Text.Json) for EmailAddress value object.