parseBodyWithConverter<T> function

T? parseBodyWithConverter<T>(
  1. List<int> bytes,
  2. JsonConverter<T> converter
)

Parse JSON body with custom type conversion

Implementation

T? parseBodyWithConverter<T>(List<int> bytes, JsonConverter<T> converter) {
  var body = utf8.decode(bytes);

  // Decode JSON
  var decoded = json.decode(body);

  try {
    // Apply converter to decoded JSON
    return converter(decoded);
  } catch (e) {
    throw FormatException('Failed to convert JSON to type $T: ${e.toString()}');
  }
}