toJson method

  1. @override
Map<String, dynamic> toJson({
  1. dynamic defaultValue,
  2. bool includeNulls = false,
})
override

Returns a Json i.e. Map<String, dynamic> representation of the BaseModel.

Implementation

@override
Map<String, dynamic> toJson({
  dynamic defaultValue,
  bool includeNulls = false,
}) {
  try {
    final className0 = this.className?.trim().nullIfEmpty;
    final fields0 = this
        .fields
        ?.map(
          (p0) => p0,
        )
        .nonNulls
        .nullIfEmpty
        ?.toList();
    final shouldInherit0 = this.shouldInherit;
    final inheritanceConstructor0 =
        this.inheritanceConstructor?.trim().nullIfEmpty;
    final keyStringCase0 = this.keyStringCase?.trim().nullIfEmpty;
    final withNulls = mergeMapsDeep([
      {
        'className': className0,
      },
      {
        'fields': fields0,
      },
      {
        'shouldInherit': shouldInherit0,
      },
      {
        'inheritanceConstructor': inheritanceConstructor0,
      },
      {
        'keyStringCase': keyStringCase0,
      },
    ]).mapWithDefault(defaultValue);
    return includeNulls ? withNulls : withNulls.nonNulls;
  } catch (e) {
    assert(false, 'GenerateModel.toJson: $e');
    rethrow;
  }
}