fromJson static method

MapSchema? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static MapSchema? 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'map_id'),
          'Required key "MapSchema[map_id]" is missing from JSON.');
      assert(json[r'map_id'] != null,
          'Required key "MapSchema[map_id]" has a null value in JSON.');
      assert(json.containsKey(r'name'),
          'Required key "MapSchema[name]" is missing from JSON.');
      assert(json[r'name'] != null,
          'Required key "MapSchema[name]" has a null value in JSON.');
      assert(json.containsKey(r'skin'),
          'Required key "MapSchema[skin]" is missing from JSON.');
      assert(json[r'skin'] != null,
          'Required key "MapSchema[skin]" has a null value in JSON.');
      assert(json.containsKey(r'x'),
          'Required key "MapSchema[x]" is missing from JSON.');
      assert(json[r'x'] != null,
          'Required key "MapSchema[x]" has a null value in JSON.');
      assert(json.containsKey(r'y'),
          'Required key "MapSchema[y]" is missing from JSON.');
      assert(json[r'y'] != null,
          'Required key "MapSchema[y]" has a null value in JSON.');
      assert(json.containsKey(r'layer'),
          'Required key "MapSchema[layer]" is missing from JSON.');
      assert(json[r'layer'] != null,
          'Required key "MapSchema[layer]" has a null value in JSON.');
      assert(json.containsKey(r'access'),
          'Required key "MapSchema[access]" is missing from JSON.');
      assert(json[r'access'] != null,
          'Required key "MapSchema[access]" has a null value in JSON.');
      assert(json.containsKey(r'interactions'),
          'Required key "MapSchema[interactions]" is missing from JSON.');
      assert(json[r'interactions'] != null,
          'Required key "MapSchema[interactions]" has a null value in JSON.');
      return true;
    }());

    return MapSchema(
      mapId: mapValueOfType<int>(json, r'map_id')!,
      name: mapValueOfType<String>(json, r'name')!,
      skin: mapValueOfType<String>(json, r'skin')!,
      x: mapValueOfType<int>(json, r'x')!,
      y: mapValueOfType<int>(json, r'y')!,
      layer: MapLayer.fromJson(json[r'layer'])!,
      access: AccessSchema.fromJson(json[r'access'])!,
      interactions: InteractionSchema.fromJson(json[r'interactions'])!,
    );
  }
  return null;
}