MapConverter.fromJson constructor
Implementation
factory MapConverter.fromJson(Map<String, Object?> json) {
final map = <String, FieldFormat>{};
for (final key in json.keys) {
final value = json[key];
if (value is String) {
map[key] = FieldFormat.preserveType(key);
} else if (value is Map<String, Object?>) {
final type = value['type'];
final named = value['name'] as String?;
if (type is Map<String, dynamic>) {
map[key] = FieldFormat.convertMap(
named: named ?? key,
destinationFormat: MapConverter.fromJson(type),
);
continue;
}
final converter = FieldFormat.defaultconverters[type];
if (converter != null) {
map[key] = FieldFormat(
name: named ?? key,
convert: converter,
);
} else {
map[key] = FieldFormat.preserveType(
named ?? key,
);
}
} else {
throw ArgumentError.value(
value,
'value',
'Invalid value for key $key in ${json[key]}',
);
}
}
return MapConverter(map: map);
}