deserialize<T> static method

T deserialize<T>(
  1. String json, [
  2. JsonSerializerOptions? options
])

Deserializes the given JSON string into an object of the specified type.

Uses the provided options or merges them with the default options. The deserialization process uses registered converters to handle type conversion.

@param json The JSON string to deserialize. @param options Optional serializer options. If provided, will be merged with default options. @returns The deserialized object of type T. @throws AssertionError if json is empty in debug mode.

Implementation

static T deserialize<T>(String json, [JsonSerializerOptions? options]) {
  assert(json.isNotEmpty, 'JSON string cannot be empty');

  final className = T.toString();
  final mergedOptions = JsonSerializer.options.merge(options);
  final type = DartParser.parseType(className);
  final parsed = JsonParser(json).parse();
  return decode(parsed, type, mergedOptions) as T;
}