deserializeFromString static method

dynamic deserializeFromString(
  1. String? json,
  2. String targetType
)

Implementation

static dynamic deserializeFromString(String? json, String targetType) {
  if (json == null) {
    // HTTP Code 204
    return null;
  }

  // Remove all spaces.  Necessary for reg expressions as well.
  targetType = targetType.replaceAll(' ', '');

  if (targetType == 'String') return json;

  final decodedJson = jsonDecode(json);
  return deserialize(decodedJson, targetType);
}