deserialize<T> static method

T deserialize<T>(
  1. String? json
)

Deserialize JSON into an object of type T.

Takes a json string as input, attempts to parse it using jsonDecode, and then uses parse to convert it into an object of type T. If any exceptions occur during this process, a JsonDeserializationException is thrown with the appropriate error message.

Throws a JsonDeserializationException with the message "JSON string is null or empty" if json is null or an empty string.

Implementation

static T deserialize<T>(String? json) {
  if (json == null || json.isEmpty) {
    throw JsonDeserializationException("JSON string is null or empty.");
  }

  return parse(jsonDecode(json), parseType<T>(), options) as T;
}