Skip to content

Non nullable fields

Ravi Teja Gudapati edited this page Jun 10, 2018 · 11 revisions

What is non-nullability?

During serialization, the non-nullable field shall be excluded if its value is null. During deserialization, the non-nullable field shall be either set to requested default value or not altered at all if its value is null.

Consider this example model:

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

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

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

{name: Lejard, age: null}

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

{name: Lejard}

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

Configure a field as non-nullable

All fields are nullable by default.

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