Skip to content
Ravi Teja Gudapati edited this page Jun 14, 2018 · 5 revisions

Jaguar automatically detects and handles immutable fields such as name, age and nationality in the following example:

class User {
  final String name;
  final int age;
  final String nationality;
  User(this.name, {this.age: 25}): nationality = 'Sweden';
}

Preserving the default values of the constructor

During deserialization, if the serialized Map contains null value for the field, the default value in the constructor will be over-written. To preserve the value set in the constructor use default value configuration through getJserDefault method.

@GenSerializer()
class UserSerializer extends Serializer<User> with _$UserSerializer {
  T getJserDefault<T>(String field) {
    switch(field) {
      case 'age': return 25 as T;
      default: return null;
    }
  }
}