fromJson static method

AttachmentMeta? fromJson(
  1. dynamic value
)

Returns a new AttachmentMeta instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static AttachmentMeta? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      assert(json.containsKey(r'id'), 'Required key "AttachmentMeta[id]" is missing from JSON.');
      assert(json[r'id'] != null, 'Required key "AttachmentMeta[id]" has a null value in JSON.');
      assert(json.containsKey(r'filename'), 'Required key "AttachmentMeta[filename]" is missing from JSON.');
      assert(json[r'filename'] != null, 'Required key "AttachmentMeta[filename]" has a null value in JSON.');
      assert(json.containsKey(r'contentType'), 'Required key "AttachmentMeta[contentType]" is missing from JSON.');
      assert(json[r'contentType'] != null, 'Required key "AttachmentMeta[contentType]" has a null value in JSON.');
      assert(json.containsKey(r'size'), 'Required key "AttachmentMeta[size]" is missing from JSON.');
      assert(json[r'size'] != null, 'Required key "AttachmentMeta[size]" has a null value in JSON.');
      return true;
    }());

    return AttachmentMeta(
      id: mapValueOfType<String>(json, r'id')!,
      filename: mapValueOfType<String>(json, r'filename')!,
      contentType: mapValueOfType<String>(json, r'contentType')!,
      size: mapValueOfType<int>(json, r'size')!,
    );
  }
  return null;
}