deserialize<T> function
Deserialize JSON into an object of type T
.
Takes a JSON String and returns an object of type T
by utilizing the
JsonSerializer.deserialize method.
Throws a JsonDeserializationException if there is an issue with the deserialization process, such as invalid JSON format or incompatible types.
If the input JSON is null
, and T
is not nullable, an error will be thrown.
Example usage:
final jsonString = '{"name": "John", "age": 30}';
final person = deserialize<Person>(jsonString);
print(person.name); // Output: John
print(person.age); // Output: 30
Implementation
T deserialize<T>(String? json) {
return JsonSerializer.deserialize<T>(json);
}