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
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 fromConverters, 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
IfTypeInfoResolver 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, bothIgnoreAuditFields() 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.
Other considerations
[JsonIgnore]is honored, as it was in 4.x.- Only types that inherit from
DbObservableObjectare affected. Other types with aDateCreatedproperty are serialized normally. IgnoreAuditFields()throwsInvalidOperationExceptionif 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