fromJSON method Null safety

  1. @override
Map? fromJSON(
  1. dynamic jsonValue,
  2. [DeserializationContext? context]
)
override

Implementation

@override
Map? fromJSON(dynamic jsonValue, [DeserializationContext? context]) {
  var result = jsonValue;
  final _typeInfo = context!.typeInfo;
  if (jsonValue is String) {
    result = _jsonDecoder.convert(jsonValue);
  }
  if (_typeInfo != null && result is Map) {
    if (_instance != null && _instance is Map || _instance == null) {
      result = result.map((key, value) => MapEntry(
          _deserializeObject(key, _typeInfo.parameters.first),
          _deserializeObject(value, _typeInfo.parameters.last)));
    }
    if (_instance != null && _instance is Map) {
      result.forEach((key, value) => _instance![key] = value);
      result = _instance;
    }
  }
  return result;
}