ITLab.Template.DevPack.JsonConverters
Provides custom System.Text.Json converters for domain-specific types and serialization edge cases.
Componentes
| Tipo | Nome | Responsabilidade |
|---|---|---|
| Class | IgnoreOffsetJsonConverter | Strips the UTC offset from ISO 8601 DateTimeOffset values during deserialization |
| Class | OneOfJsonConverter | Handles serialization and deserialization of OneOf<T0, T1, ...> discriminated unions |
| Class | RoundedDoubleJsonConverter | Reads and writes RoundedDouble struct values with consistent decimal precision |
Como usar
// Register converters globally in the JSON options.
services.ConfigureHttpJsonOptions(opts =>
{
opts.SerializerOptions.Converters.Add(new IgnoreOffsetJsonConverter());
opts.SerializerOptions.Converters.Add(new RoundedDoubleJsonConverter());
});
O que não fazer
- Do not use
IgnoreOffsetJsonConverterwhen the consumer requires timezone-aware datetimes. - Do not register duplicate converter instances for the same type.
Extensão pelo produto
- Products can add converters for product-specific value objects by following the
JsonConverter<T>pattern used in this namespace.