Skip to content

Feature Request Remove objects where all fields are null #1491

Open
@martipello

Description

@martipello

Hopefully this already has a solution, but i want to request a flag similar to includeIfNull which removes an object where all its fields are null, so given

@freezed
class Transfer with _$Transfer {
    @JsonSerializable(explicitToJson: true, includeIfNull: false)
    const factory Transfer({
    String? provider,
    String? comment,
    double? amount,
  }) = _Transfer;

  factory Transfer.fromJson(Map<String, dynamic> json) => _$TransferFromJson(json);

}`

Given the model is nested in a parent
if all fields were null the output would be :

{
   "transfer": {}
}

without includeIfNull the output would be :

{
   "transfer":{
      "provider":null,
      "comment":null,
      "amount":null
   }
}

i am requesting a flag to make the output :

{}

currently i have to make a check that any of these fields are not null before i include the object, so if there is a better way please let me know.

Many thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions