fromJson static method

FlightSearchRequest? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static FlightSearchRequest? 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'slices'), 'Required key "FlightSearchRequest[slices]" is missing from JSON.');
      assert(json[r'slices'] != null, 'Required key "FlightSearchRequest[slices]" has a null value in JSON.');
      assert(json.containsKey(r'passengers'), 'Required key "FlightSearchRequest[passengers]" is missing from JSON.');
      assert(json[r'passengers'] != null, 'Required key "FlightSearchRequest[passengers]" has a null value in JSON.');
      return true;
    }());

    return FlightSearchRequest(
      slices: FlightSearchSlice.listFromJson(json[r'slices']),
      passengers: FlightSearchPassenger.listFromJson(json[r'passengers']),
      cabinClass: FlightSearchRequestCabinClassEnum.fromJson(json[r'cabinClass']),
      filters: FlightSearchFilters.fromJson(json[r'filters']),
      page: mapValueOfType<int>(json, r'page'),
      limit: mapValueOfType<int>(json, r'limit'),
      currency: mapValueOfType<String>(json, r'currency'),
    );
  }
  return null;
}