fromJson static method

ExtractTextResult? fromJson(
  1. dynamic value
)

Returns a new ExtractTextResult instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static ExtractTextResult? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      assert(json.containsKey(r'text'), 'Required key "ExtractTextResult[text]" is missing from JSON.');
      assert(json[r'text'] != null, 'Required key "ExtractTextResult[text]" has a null value in JSON.');
      assert(json.containsKey(r'pageCount'), 'Required key "ExtractTextResult[pageCount]" is missing from JSON.');
      assert(json[r'pageCount'] != null, 'Required key "ExtractTextResult[pageCount]" has a null value in JSON.');
      return true;
    }());

    return ExtractTextResult(
      text: mapValueOfType<String>(json, r'text')!,
      pageCount: mapValueOfType<int>(json, r'pageCount')!,
      pages: Map.listFromJson(json[r'pages']),
      truncated: mapValueOfType<bool>(json, r'truncated'),
    );
  }
  return null;
}