Skip to content

Non nullable fields

Ravi Teja Gudapati edited this page May 31, 2018 · 11 revisions

A non-nullable field shall be excluded during serialization, if its value is null.

Consider this example model:

class Player {
  String name;
  int age;
  Player({this.name, this.age});
}

playerSerializer.to(Player(name: 'Lejard'));

If field age is nullable, the above code would print:

{name: Lejard, age: null}

If age is configured to be nullable, the above code would print:

{name: Lejard}

Notice how the non-nullable field age is skipped when its value is null.

All fields are nullable by default.

{{ TODO msg="How to make a field non-nullable" }}