@@ -627,9 +627,152 @@ class DateTimeUtcTestClass {
627627 DateTimeUtcTestClass (this .date);
628628}
629629
630+ @ShouldThrow (
631+ 'Could not generate `fromJson` code for `record` because of type '
632+ '`void Function()`.' ,
633+ )
634+ @JsonSerializable ()
635+ class RecordWithFunction {
636+ final (int , void Function ()) record;
637+
638+ RecordWithFunction (this .record);
639+ }
640+
641+ @ShouldThrow (
642+ 'Could not generate `fromJson` code for `record` because of type '
643+ '`void Function()`.' ,
644+ )
645+ @JsonSerializable ()
646+ class RecordWithNamedFunction {
647+ final ({int a, void Function () b}) record;
648+
649+ RecordWithNamedFunction (this .record);
650+ }
651+
652+ @ShouldThrow (
653+ 'Could not generate `fromJson` code for `record` because of type '
654+ '`void Function()`.' ,
655+ )
656+ @JsonSerializable ()
657+ class RecordWithSinglePositionalFunction {
658+ final (void Function (),) record;
659+
660+ RecordWithSinglePositionalFunction (this .record);
661+ }
662+
663+ class RecordConverter1 extends JsonConverter <(int , int ), Map <String , dynamic >> {
664+ const RecordConverter1 ();
665+ @override
666+ (int , int ) fromJson (Map <String , dynamic > json) => (0 , 0 );
667+ @override
668+ Map <String , dynamic > toJson ((int , int ) object) => {};
669+ }
670+
671+ class RecordConverter2 extends JsonConverter <(int , int ), Map <String , dynamic >> {
672+ const RecordConverter2 ();
673+ @override
674+ (int , int ) fromJson (Map <String , dynamic > json) => (0 , 0 );
675+ @override
676+ Map <String , dynamic > toJson ((int , int ) object) => {};
677+ }
678+
679+ @ShouldThrow ('Found more than one matching converter for `(int, int)`.' )
680+ @JsonSerializable ()
681+ @RecordConverter 1()
682+ @RecordConverter 2()
683+ class RecordDoubleConverter {
684+ late (int , int ) record;
685+ }
686+
687+ class SingleRecordConverter1
688+ extends JsonConverter <(int ,), Map <String , dynamic >> {
689+ const SingleRecordConverter1 ();
690+ @override
691+ (int ,) fromJson (Map <String , dynamic > json) => (0 ,);
692+ @override
693+ Map <String , dynamic > toJson ((int ,) object) => {};
694+ }
695+
696+ class SingleRecordConverter2
697+ extends JsonConverter <(int ,), Map <String , dynamic >> {
698+ const SingleRecordConverter2 ();
699+ @override
700+ (int ,) fromJson (Map <String , dynamic > json) => (0 ,);
701+ @override
702+ Map <String , dynamic > toJson ((int ,) object) => {};
703+ }
704+
705+ @ShouldThrow ('Found more than one matching converter for `(int,)`.' )
706+ @JsonSerializable ()
707+ @SingleRecordConverter 1()
708+ @SingleRecordConverter 2()
709+ class RecordSingleDoubleConverter {
710+ late (int ,) record;
711+ }
712+
713+ class NullableRecordConverter1
714+ extends JsonConverter <(int , int )?, Map <String , dynamic >> {
715+ const NullableRecordConverter1 ();
716+ @override
717+ (int , int )? fromJson (Map <String , dynamic > json) => null ;
718+ @override
719+ Map <String , dynamic > toJson ((int , int )? object) => {};
720+ }
721+
722+ class NullableRecordConverter2
723+ extends JsonConverter <(int , int )?, Map <String , dynamic >> {
724+ const NullableRecordConverter2 ();
725+ @override
726+ (int , int )? fromJson (Map <String , dynamic > json) => null ;
727+ @override
728+ Map <String , dynamic > toJson ((int , int )? object) => {};
729+ }
730+
731+ @ShouldThrow ('Found more than one matching converter for `(int, int)?`.' )
732+ @JsonSerializable ()
733+ @NullableRecordConverter 1()
734+ @NullableRecordConverter 2()
735+ class RecordNullableDoubleConverter {
736+ late (int , int )? record;
737+ }
738+
739+ class NamedRecordConverter1
740+ extends JsonConverter <({int a, int b}), Map <String , dynamic >> {
741+ const NamedRecordConverter1 ();
742+ @override
743+ ({int a, int b}) fromJson (Map <String , dynamic > json) => (a: 0 , b: 0 );
744+ @override
745+ Map <String , dynamic > toJson (({int a, int b}) object) => {};
746+ }
747+
748+ class NamedRecordConverter2
749+ extends JsonConverter <({int a, int b}), Map <String , dynamic >> {
750+ const NamedRecordConverter2 ();
751+ @override
752+ ({int a, int b}) fromJson (Map <String , dynamic > json) => (a: 0 , b: 0 );
753+ @override
754+ Map <String , dynamic > toJson (({int a, int b}) object) => {};
755+ }
756+
757+ @ShouldThrow ('Found more than one matching converter for `({int a, int b})`.' )
758+ @JsonSerializable ()
759+ @NamedRecordConverter 1()
760+ @NamedRecordConverter 2()
761+ class RecordNamedDoubleConverter {
762+ late ({int a, int b}) record;
763+ }
764+
630765@ShouldThrow ('''
631- Could not generate `fromJson` code for `field` because type is unimplemented (UnimplementedError: (FunctionTypeImpl) void Function()) .''' )
766+ Could not generate `fromJson` code for `field` because of type ` void Function()` .''' )
632767@JsonSerializable (createToJson: false )
633768class UnsupportedNestedFunctionType {
634769 late List <void Function ()> field;
635770}
771+
772+ @ShouldThrow ('''
773+ Could not generate `fromJson` code for `map` because of type `(int, int)`.
774+ Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.''' )
775+ @JsonSerializable (createToJson: false )
776+ class UnsupportedMapKeyRecord {
777+ late Map <(int , int ), String > map;
778+ }
0 commit comments