toEntity<R extends BaseEntity> method

  1. @override
R? toEntity<R extends BaseEntity>()
override

Implementation

@override
R? toEntity<R extends BaseEntity>() {
  try {
    dynamic data = body;

    if (body.runtimeType == String) data = json.decode(body);

    if (body is List) {
      List<T> entities =
          List<T>.from(data.map((model) => getInstance<R>(data)));
      return entities as R;
    }

    return getInstance<R>(data);
  } on TypeError catch (e) {
    logger.error(e);
    return null;
  }
}