PosInformatique.Foundations.PhoneNumbers.Json 1.0.0

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

PosInformatique.Foundations.PhoneNumbers.Json

NuGet version NuGet downloads

Introduction

This package provides System.Text.Json integration for the PhoneNumber value object from PosInformatique.Foundations.PhoneNumbers.

It adds a JsonConverter<PhoneNumber> that serializes and deserializes phone numbers as JSON strings in E.164 format, and an extension method to easily register the converter on your JsonSerializerOptions.

Install

You can install the package from NuGet:

dotnet add package PosInformatique.Foundations.PhoneNumbers.Json

Features

  • System.Text.Json converter for the PhoneNumber value object
  • Serializes PhoneNumber as a JSON string in E.164 format
  • Deserializes from a JSON string to a PhoneNumber instance
  • Gracefully handles null and empty/whitespace JSON string values as null
  • Convenient extension method AddPhoneNumbersConverters on JsonSerializerOptions

Use cases

  • Persist and exchange PhoneNumber values as JSON with APIs
  • Use PhoneNumber in your DTOs without custom mapping code
  • Share a consistent JSON representation (E.164) across microservices and clients

Examples

Register the converter globally

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

// Configure JsonSerializerOptions
var options = new JsonSerializerOptions()
    .AddPhoneNumbersConverters();

Serialize a PhoneNumber

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

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

PhoneNumber phone = "+33123456789";

var json = JsonSerializer.Serialize(phone, options);
// json == "\"+33123456789\""

Deserialize a PhoneNumber

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

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

var json = "\"+33123456789\"";

var phone = JsonSerializer.Deserialize<PhoneNumber>(json, options);
// phone represents "+33123456789"

Use PhoneNumber in DTOs

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

public sealed class ContactDto
{
    public string Name { get; set; } = default!;
    public PhoneNumber? Mobile { get; set; }
}

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

var contact = new ContactDto
{
    Name = "John Doe",
    Mobile = PhoneNumber.Parse("+33123456789")
};

var json = JsonSerializer.Serialize(contact, options);
// {
//   "Name": "John Doe",
//   "Mobile": "+33123456789"
// }

var deserialized = JsonSerializer.Deserialize<ContactDto>(json, options);

Handling null and empty values

  • JSON null is deserialized as null PhoneNumber.
  • Empty or whitespace JSON strings are also deserialized as null.
var options = new JsonSerializerOptions().AddPhoneNumbersConverters();

var jsonNull = "null";
var phoneNull = JsonSerializer.Deserialize<PhoneNumber?>(jsonNull, options); // null

var jsonEmpty = "\"\"";
var phoneEmpty = JsonSerializer.Deserialize<PhoneNumber?>(jsonEmpty, options); // null
Product Compatible and additional computed target framework versions.
.NET 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.  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 333 11/19/2025
1.0.0-rc.4 320 11/19/2025
1.0.0-rc.3 327 11/18/2025
1.0.0-rc.2 325 11/18/2025
1.0.0-rc.1 329 11/18/2025

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