Part.fromJson constructor

Part.fromJson(
  1. Map<String, Object?> json, {
  2. required Map<String, JsonToPartConverter<Part>> converterRegistry,
})

Deserializes a part from a JSON map.

The converterRegistry parameter is a map of part types to converters.

Implementation

factory Part.fromJson(
  Map<String, Object?> json, {
  required Map<String, JsonToPartConverter> converterRegistry,
}) {
  final type = json[typeKey] as String;
  final JsonToPartConverter? converter = converterRegistry[type];
  if (converter == null) {
    throw UnimplementedError('Unknown part type: $type');
  }
  return converter.convert(json);
}