JsonConverterExtensions Class
Definition
- Namespace
- Savvyio.Extensions.Newtonsoft.Json
- Assemblies
- Savvyio.Extensions.Newtonsoft.Json.dll
Extension methods for the Newtonsoft.Json.JsonConverter class.
public static class JsonConverterExtensions
- Inheritance
-
objectJsonConverterExtensions
Examples
Use JsonConverterExtensions to add all Savvy I/O-aware converters to a Newtonsoft.Json serializer configuration.
using Savvyio;
using System;
using Newtonsoft.Json;
using Savvyio.Commands;
using Savvyio.Domain;
using Savvyio.Extensions.Newtonsoft.Json;
using Savvyio.Messaging;
namespace ExampleApp;
public static class JsonSettingsFactory
{
public static JsonSerializerSettings Create()
{
var settings = new JsonSerializerSettings();
settings.Converters
.AddMetadataDictionaryConverter()
.AddMessageConverter()
.AddRequestConverter()
.AddSingleValueObjectConverter()
.AddValueObjectConverter()
.AddAggregateRootConverter<Guid>();
var message = new Message<PublishOrderCommand>(
"msg-001",
new Uri("urn:orders"),
nameof(PublishOrderCommand),
new PublishOrderCommand("SO-42"),
DateTime.UtcNow);
_ = JsonConvert.SerializeObject(message, settings);
return settings;
}
}
public sealed record PublishOrderCommand(string OrderId) : Request;
Methods
| Name | Description |
|---|---|
| AddAggregateRootConverter<TKey>(ICollection<JsonConverter>, Action<ActivatorOptions>) | Adds a AggregateRoot<TKey> converter to the collection. |
| AddMessageConverter(ICollection<JsonConverter>) | Adds an IMessage<T>/ISignedMessage<T> converter to the collection. |
| AddMetadataDictionaryConverter(ICollection<JsonConverter>) | Adds a IMetadataDictionary converter to the collection. |
| AddRequestConverter(ICollection<JsonConverter>) | Adds an IRequest converter to the collection. |
| AddSingleValueObjectConverter(ICollection<JsonConverter>) | Adds a SingleValueObject<T> converter to the collection. |
| AddValueObjectConverter(ICollection<JsonConverter>, Action<ActivatorOptions>) | Adds a ValueObject converter to the collection. |