@JsonSerializable
class PatchUserDTO {
final String? name;
final DateTime? birthday;
...OTHER STAFF...
}
But I need to differentiate between birthday == null
and birthday
is not set.
I guess, nice solution would be
class Optional<T> {
final T? value;
Optional(this.value);
T? toJson() => value;
}
@JsonSerializable
class PatchUserDTO {
final String? name;
@JsonKey(includeIfNull: false)
final Optional<DateTime>? birthday;
...OTHER STAFF...
}
But includeIfNull
is applied to finalised json. So if Optional<DateTime>
is not null
, but value
is null, it still won't be serialized.