fromJSON method

  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,
              context,
              typeInfo.parameters.isEmpty
                  ? String
                  : typeInfo.parameters.first),
          _deserializeObject(
              value,
              context,
              typeInfo.parameters.isEmpty
                  ? dynamic
                  : typeInfo.parameters.last)));
    }
    if (_instance != null && _instance is Map) {
      result.forEach((key, value) => _instance![key] = value);
      result = _instance;
    }
  }
  return result;
}