dkpModelFromJsonString<T> function

T? dkpModelFromJsonString<T>({
  1. required String serialized,
  2. required Serializer<T> serializer,
})

Deserializes a JSON string into an object of type T, using the provided serializer.

This function attempts to convert a JSON string representation into an instance of T, where T extends Built<T,V> and V extends Builder<T,V>, using the specified serializer. It utilizes the standardSerializers.fromJson method from the Built package to perform the deserialization. If the deserialization fails, it logs the error and returns null.

Parameters:

  • serialized: The JSON string to be deserialized.
  • serializer: An instance of Serializer<T> that defines how to deserialize the JSON string.

Returns: An instance of T if successful, or null if deserialization fails due to an error.

Implementation

T? dkpModelFromJsonString<T>({
  required String serialized,
  required Serializer<T> serializer,
}) {
  try {
    T? model = standardSerializers.fromJson<T>(serializer, serialized);
    return model;
  } on DeserializationError {
    return null;
  } on Exception {
    rethrow;
  }
}