Skip to main content

Definition

Assembly: CloudNimble.EasyAF.Core.dll Namespace: CloudNimble.EasyAF.Core.Converters Inheritance: System.Text.Json.Serialization.JsonConverter<T>

Syntax

Summary

A JsonConverter`1 that ignores the audit properties on a DbObservableObject.

Usage

IgnoreAuditFieldsJsonConverter and IgnoreAuditFieldsJsonConverterFactory are obsolete as of EasyAF 5.0. Call IgnoreAuditFields() on your JsonSerializerOptions instead.
IgnoreAuditFields() stops DateCreated, CreatedById, DateUpdated, and UpdatedById from being written when any DbObservableObject is serialized. Audit fields are still read when deserializing. Use it on the client when you send entities back to an API, so the server stays the only source of audit values.

Migrating from the converter

Remove the factory from Converters, and chain IgnoreAuditFields() onto the options:
IgnoreAuditFields() returns the same instance, and must be called before the options are first used.

Native AOT and source generation

If TypeInfoResolver is already set, IgnoreAuditFields() adds to it instead of replacing it, so it works with a source-generated context:

Performance

The audit properties are removed from each type’s serialization contract once, the first time that type is serialized. After that, serialization runs at the same speed as plain System.Text.Json. The 4.x converter used reflection on every call. In EasyAF’s benchmarks, serializing an entity dropped from 1,545.0 ns and 5,240 B to 111.2 ns and 416 B. See the release notes for the full comparison.

Remarks

As of EasyAF 5.0, this converter delegates to the same contract modifier as JsonSerializerOptions), so every System.Text.Json setting is honored.

Considerations

Output changes in EasyAF 5.0

In 5.0, both IgnoreAuditFields() and the obsolete converter let System.Text.Json write the whole object, so every serializer setting applies. The 4.x converter wrote each property itself, and skipped several settings. If you depend on the 4.x output, here is what changed and how to restore it.
If your options use JsonIgnoreCondition.WhenWritingDefault, check any POST or PATCH that depends on sending false, 0, or Guid.Empty. Those values are no longer written, so the server’s default value is used instead.

Other considerations

  • [JsonIgnore] is honored, as it was in 4.x.
  • Only types that inherit from DbObservableObject are affected. Other types with a DateCreated property are serialized normally.
  • IgnoreAuditFields() throws InvalidOperationException if the options have already been used, because System.Text.Json makes options read-only after first use.

Constructors

.ctor

Syntax

Parameters

Properties

HandleNull Override

Syntax

Property Value

Type: bool

Methods

Read Override

Syntax

Parameters

Returns

Type: T

Write Override

Syntax

Parameters