Pular para o conteúdo principal
Versão: 10.4.1

ITLab.Template.DevPack.JsonConverters

Provides custom System.Text.Json converters for domain-specific types and serialization edge cases.

Componentes

TipoNomeResponsabilidade
ClassIgnoreOffsetJsonConverterStrips the UTC offset from ISO 8601 DateTimeOffset values during deserialization
ClassOneOfJsonConverterHandles serialization and deserialization of OneOf<T0, T1, ...> discriminated unions
ClassRoundedDoubleJsonConverterReads 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 IgnoreOffsetJsonConverter when 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.