fromJson static method

MixedOrderRequestItem? fromJson(
  1. dynamic value
)

Returns a new MixedOrderRequestItem from a decoded JSON object, or null for something that is not an object. Throws a FormatException when no variant fits: skipping it would hide a purchase or a price.

Implementation

static MixedOrderRequestItem? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();
    switch (json[r'productType']) {
      case "esim":
        final variant = EsimMixedOrderRequestItem.fromJson(json);
        return variant == null ? null : MixedOrderRequestItem(variant);
      case "hotel":
        final variant = HotelMixedOrderRequestItem.fromJson(json);
        return variant == null ? null : MixedOrderRequestItem(variant);
      case "flight":
        final variant = FlightMixedOrderRequestItem.fromJson(json);
        return variant == null ? null : MixedOrderRequestItem(variant);
      case "giftCard":
        final variant = GiftCardMixedOrderRequestItem.fromJson(json);
        return variant == null ? null : MixedOrderRequestItem(variant);
      case "airtime":
        final variant = AirtimeMixedOrderRequestItem.fromJson(json);
        return variant == null ? null : MixedOrderRequestItem(variant);
      case "utility":
        final variant = UtilityMixedOrderRequestItem.fromJson(json);
        return variant == null ? null : MixedOrderRequestItem(variant);
    }
    throw FormatException('Unknown productType ${json[r'productType']} in MixedOrderRequestItem');
  }
  return null;
}