Provides Newtonsoft.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 Newtonsoft.Json serialization patterns.
$ dotnet add package UUID.Serialization.NewtonsoftA Newtonsoft.Json serialization provider for the UUID library.
dotnet add package UUID.Serialization.Newtonsoft
using Newtonsoft.Json;
// Register the converter globally
JsonSerializerSettings settings = new()
{
Converters = { new UUIDConverter() }
};
// Serialize
var uuid = new UUID();
string json = JsonConvert.SerializeObject(uuid, settings);
// Deserialize
UUID deserializedUuid = JsonConvert.DeserializeObject<UUID>(json, settings);
public class UserModel
{
public UUID Id { get; set; }
public string Name { get; set; }
}
// Register converter
JsonSerializerSettings settings = new()
{
Converters = { new UUIDConverter() }
};
// Serialize model
var user = new UserModel
{
Id = new UUID(),
Name = "John Doe"
};
string json = JsonConvert.SerializeObject(user, settings);
// Deserialize model
UserModel deserializedUser = JsonConvert.DeserializeObject<UserModel>(json, settings);
public class UserModel
{
[JsonConverter(typeof(UUIDConverter))]
public UUID Id { get; set; }
public string Name { get; set; }
}
// No need to register converter globally
var user = new UserModel
{
Id = new UUID(),
Name = "John Doe"
};
string json = JsonConvert.SerializeObject(user);
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.