fromJson static method

EffectSchema? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static EffectSchema? 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'name'),
          'Required key "EffectSchema[name]" is missing from JSON.');
      assert(json[r'name'] != null,
          'Required key "EffectSchema[name]" has a null value in JSON.');
      assert(json.containsKey(r'code'),
          'Required key "EffectSchema[code]" is missing from JSON.');
      assert(json[r'code'] != null,
          'Required key "EffectSchema[code]" has a null value in JSON.');
      assert(json.containsKey(r'description'),
          'Required key "EffectSchema[description]" is missing from JSON.');
      assert(json[r'description'] != null,
          'Required key "EffectSchema[description]" has a null value in JSON.');
      assert(json.containsKey(r'type'),
          'Required key "EffectSchema[type]" is missing from JSON.');
      assert(json[r'type'] != null,
          'Required key "EffectSchema[type]" has a null value in JSON.');
      assert(json.containsKey(r'subtype'),
          'Required key "EffectSchema[subtype]" is missing from JSON.');
      assert(json[r'subtype'] != null,
          'Required key "EffectSchema[subtype]" has a null value in JSON.');
      return true;
    }());

    return EffectSchema(
      name: mapValueOfType<String>(json, r'name')!,
      code: mapValueOfType<String>(json, r'code')!,
      description: mapValueOfType<String>(json, r'description')!,
      type: EffectType.fromJson(json[r'type'])!,
      subtype: EffectSubtype.fromJson(json[r'subtype'])!,
    );
  }
  return null;
}