tryDeserialize static method

DsaReportRequest tryDeserialize(
  1. Map<String, dynamic> json, {
  2. String key = 'report_type',
  3. Map<Type, Object?>? mapping,
})

Implementation

static DsaReportRequest tryDeserialize(
  Map<String, dynamic> json, {
  String key = 'report_type',
  Map<Type, Object?>? mapping,
}) {
  final mappingFallback = const <Type, Object?>{
    DsaReportRequestMessage: 'message',
    DsaReportRequestUser: 'user',
    DsaReportRequestGuild: 'guild',
  };
  final value = json[key];
  final effective = mapping ?? mappingFallback;
  return switch (value) {
    _ when value == effective[DsaReportRequestMessage] =>
      DsaReportRequestMessage.fromJson(json),
    _ when value == effective[DsaReportRequestUser] =>
      DsaReportRequestUser.fromJson(json),
    _ when value == effective[DsaReportRequestGuild] =>
      DsaReportRequestGuild.fromJson(json),
    _ => throw FormatException(
      'Unknown discriminator value "${json[key]}" for DsaReportRequest',
    ),
  };
}