It would be great to be able to configure dart_mappable, so that it returns null instead of throwing an exception or returning the class annotated with MappableClass.useAsDefault, when there is an unknown discriminator value.
Basically, it should do the same as this example does:
import 'dart:convert';
void main(List<String> arguments) {
final json = '{"type": "start"}';
final type = jsonDecode(json)["type"];
final event = switch (type) {
"start" => Start(),
"end" => End(),
_ => null,
};
}
sealed class Event {}
class Start implements Event {}
class End implements Event {}
It would be great to be able to configure dart_mappable, so that it returns
nullinstead of throwing an exception or returning the class annotated withMappableClass.useAsDefault, when there is an unknown discriminator value.Basically, it should do the same as this example does: