> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.nimbleapps.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# IgnoreAuditFieldsJsonConverter

> A [JsonConverter`1](https://learn.microsoft.com/dotnet/api/system.text.json.serialization.jsonconverter-1) that ignores the audit properties on a [DbObservab...

## Definition

**Assembly:** CloudNimble.EasyAF.Core.dll

**Namespace:** CloudNimble.EasyAF.Core.Converters

**Inheritance:** System.Text.Json.Serialization.JsonConverter\<T>

## Syntax

```csharp theme={"dark"}
CloudNimble.EasyAF.Core.Converters.IgnoreAuditFieldsJsonConverter<T>
```

## Summary

A [JsonConverter\`1](https://learn.microsoft.com/dotnet/api/system.text.json.serialization.jsonconverter-1) that ignores the audit properties on a [DbObservableObject](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Core/DbObservableObject).

## Usage

> [!WARNING]
>
> `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:

```csharp theme={"dark"}
// EasyAF 4.x
private JsonSerializerOptions jsonSerializerOptions = new()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
Converters =
{
    new JsonStringEnumConverter(),
    new IgnoreAuditFieldsJsonConverterFactory()
},
TypeInfoResolver = new DefaultJsonTypeInfoResolver()
};

// EasyAF 5.0
private JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
Converters = { new JsonStringEnumConverter() },
}.IgnoreAuditFields();
```

`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:

```csharp theme={"dark"}
[JsonSerializable(typeof(Scenario))]
internal partial class AppJsonContext : JsonSerializerContext;

var options = new JsonSerializerOptions
{
TypeInfoResolver = AppJsonContext.Default,
}.IgnoreAuditFields();
```

## 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](https://easyaf.nimbleapps.cloud/release-notes.md) for the full comparison.

## Remarks

As of EasyAF 5.0, this converter delegates to the same contract modifier as
[JsonSerializerOptions)](https://learn.microsoft.com/dotnet/api/system.text.json.easyaf_jsonserializeroptionsextensions.ignoreauditfields\(system.text.json.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.

| Change | 4.x output | 5.0 output | To restore the 4.x output |
| - | - | - | - |
| `DefaultIgnoreCondition` | Only `null` values were skipped, even with `WhenWritingDefault`. `0`, `false`, and `Guid.Empty` were written. | `WhenWritingDefault` also skips `0`, `false`, and `Guid.Empty`. | Use `JsonIgnoreCondition.WhenWritingNull`. |
| Naming policies and `[JsonPropertyName]` | Top-level property names were always the C# names. | The naming policy and `[JsonPropertyName]` apply. | Remove `PropertyNamingPolicy` from these options. |
| Related entities | Audit fields were still written on related entities (for example, `Order.Customer.DateCreated`). | Audit fields are removed on every `DbObservableObject` in the graph. | Serialize the related entity separately, with options that do not call `IgnoreAuditFields()`. |
| Property types | Values were written using their runtime type. | Values are written using their declared type, like the rest of System.Text.Json. | Add `[JsonDerivedType]` to the base type, or declare the property as `object`. |

> [!WARNING]
>
> 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

### &#x20;.ctor

#### Syntax

```csharp theme={"dark"}
public IgnoreAuditFieldsJsonConverter(System.Text.Json.JsonSerializerOptions options)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `options` | `System.Text.Json.JsonSerializerOptions` | - |

## Properties

### &#x20;HandleNull Override

#### Syntax

```csharp theme={"dark"}
public override bool HandleNull { get; }
```

#### Property Value

Type: `bool`

## Methods

### &#x20;Read Override

#### Syntax

```csharp theme={"dark"}
public override T Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `reader` | `System.Text.Json.Utf8JsonReader` | - |
| `typeToConvert` | `System.Type` | - |
| `options` | `System.Text.Json.JsonSerializerOptions` | - |

#### Returns

Type: `T`

### &#x20;Write Override

#### Syntax

```csharp theme={"dark"}
public override void Write(System.Text.Json.Utf8JsonWriter writer, T value, System.Text.Json.JsonSerializerOptions options)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `writer` | `System.Text.Json.Utf8JsonWriter` | - |
| `value` | `T` | - |
| `options` | `System.Text.Json.JsonSerializerOptions` | - |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.