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
<PackageReference Include="PosInformatique.Foundations.PhoneNumbers.Json" Version="1.0.0" />
<PackageVersion Include="PosInformatique.Foundations.PhoneNumbers.Json" Version="1.0.0" />
<PackageReference Include="PosInformatique.Foundations.PhoneNumbers.Json" />
paket add PosInformatique.Foundations.PhoneNumbers.Json --version 1.0.0
#r "nuget: PosInformatique.Foundations.PhoneNumbers.Json, 1.0.0"
#:package PosInformatique.Foundations.PhoneNumbers.Json@1.0.0
#addin nuget:?package=PosInformatique.Foundations.PhoneNumbers.Json&version=1.0.0
#tool nuget:?package=PosInformatique.Foundations.PhoneNumbers.Json&version=1.0.0
PosInformatique.Foundations.PhoneNumbers.Json
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.Jsonconverter for thePhoneNumbervalue object- Serializes
PhoneNumberas a JSON string in E.164 format - Deserializes from a JSON string to a
PhoneNumberinstance - Gracefully handles
nulland empty/whitespace JSON string values asnull - Convenient extension method
AddPhoneNumbersConvertersonJsonSerializerOptions
Use cases
- Persist and exchange
PhoneNumbervalues as JSON with APIs - Use
PhoneNumberin 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
nullis deserialized asnullPhoneNumber. - 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
Links
| Product | Versions 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. |
-
net8.0
- PosInformatique.Foundations.PhoneNumbers (>= 1.0.0)
-
net9.0
- PosInformatique.Foundations.PhoneNumbers (>= 1.0.0)
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.