explicitJsonNullWhenNonNullField property

bool? explicitJsonNullWhenNonNullField
final

Enables PATCH-style tri-state semantics for this field.

When true, generated toJson omits the JSON key only when the Dart field is null, but still writes "key": null when the field is non-null and serialization yields JSON null.

Generated fromJson uses Map.containsKey to distinguish a missing key (typically decoded as Dart null on a nullable field) from an explicit JSON null (decoded via the field's fromJson path with a null argument). The field type must be nullable, and any custom fromJson function must accept a nullable JSON input for the explicit-null case.

Cannot be combined with disallowNullValue, required, defaultValue, or readValue. Setting this flag to true overrides includeIfNull.

Implementation

final bool? explicitJsonNullWhenNonNullField;