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 EasyAF_JsonSerializerOptionsExtensions.IgnoreAuditFields, 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
.ctor Inherited
Inherited from
System.Text.Json.Serialization.JsonConverter<T>Syntax
.ctor Inherited
Inherited from
objectSyntax
Properties
HandleNull Override
Syntax
Property Value
Type:bool
HandleNull Inherited Virtual
Inherited from
System.Text.Json.Serialization.JsonConverter<T>Syntax
Property Value
Type:bool
Type Override
Inherited from
System.Text.Json.Serialization.JsonConverter<T>Syntax
Property Value
Type:System.Type
Type Inherited Abstract
Inherited from
System.Text.Json.Serialization.JsonConverterSyntax
Property Value
Type:System.Type?
Methods
CanConvert Override
Inherited from
System.Text.Json.Serialization.JsonConverter<T>Syntax
Parameters
Returns
Type:bool
CanConvert Inherited Abstract
Inherited from
System.Text.Json.Serialization.JsonConverterSyntax
Parameters
Returns
Type:bool
Equals Inherited Virtual
Inherited from
objectSyntax
Parameters
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
GetHashCode Inherited Virtual
Inherited from
objectSyntax
Returns
Type:int
GetType Inherited
Inherited from
objectSyntax
Returns
Type:System.Type
MemberwiseClone Inherited
Inherited from
objectSyntax
Returns
Type:object
Read Override
Syntax
Parameters
Returns
Type:T
Read Inherited Abstract
Inherited from
System.Text.Json.Serialization.JsonConverter<T>Syntax
Parameters
Returns
Type:T?
ReadAsPropertyName Inherited Virtual
Inherited from
System.Text.Json.Serialization.JsonConverter<T>Syntax
Parameters
Returns
Type:T
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
ToString Inherited Virtual
Inherited from
objectSyntax
Returns
Type:string?
Write Override
Syntax
Parameters
Write Inherited Abstract
Inherited from
System.Text.Json.Serialization.JsonConverter<T>Syntax
Parameters
WriteAsPropertyName Inherited Virtual
Inherited from
System.Text.Json.Serialization.JsonConverter<T>