Provides System.Text.Json serialization support for the UUID library, enabling seamless JSON serialization and deserialization of UUID values. Features include efficient string conversion, comprehensive error handling, and full compatibility with System.Text.Json serialization patterns.
$ dotnet add package UUID.Serialization.SystemA System.Text.Json serialization provider for the UUID library.
dotnet add package UUID.Serialization.System
using System.Text.Json;
// Register the converter globally
JsonSerializerOptions options = new()
{
Converters = { new UUIDConverter() }
};
// Serialize
var uuid = new UUID();
string json = JsonSerializer.Serialize(uuid, options);
// Deserialize
UUID deserializedUuid = JsonSerializer.Deserialize<UUID>(json, options);
public class UserModel
{
public UUID Id { get; set; }
public string Name { get; set; }
}
// Register converter
JsonSerializerOptions options = new()
{
Converters = { new UUIDConverter() }
};
// Serialize model
var user = new UserModel
{
Id = new UUID(),
Name = "John Doe"
};
string json = JsonSerializer.Serialize(user, options);
// Deserialize model
UserModel deserializedUser = JsonSerializer.Deserialize<UserModel>(json, options);
The converter provides detailed error messages for common scenarios:
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the terms of the LICENSE file included in the root directory.