@@ -55,7 +55,12 @@ Uint8List? tryToJson(CType type, dynamic value) {
55
55
// obj may be a map, must be ignore.
56
56
value is ! Map ) {
57
57
try {
58
- return type.encodeValue (value.toJson ());
58
+ try {
59
+ value = value.toIDLSerializable ();
60
+ } on NoSuchMethodError {
61
+ value = value.toJson ();
62
+ }
63
+ return type.encodeValue (value);
59
64
} catch (e) {
60
65
return null ;
61
66
}
@@ -528,9 +533,7 @@ class NatClass extends PrimitiveType {
528
533
529
534
@override
530
535
bool covariant (x) {
531
- return (x is BigInt && x >= BigInt .zero) ||
532
- (x is int && x >= 0 ) ||
533
- (x is String && BigInt .parse (x) >= BigInt .zero);
536
+ return (x is BigInt && x >= BigInt .zero) || (x is int && x >= 0 );
534
537
}
535
538
536
539
@override
@@ -636,9 +639,6 @@ class FixedIntClass extends PrimitiveType {
636
639
} else if (x is int ) {
637
640
final v = BigInt .from (x);
638
641
return v >= min && v <= max;
639
- } else if (x is String && BigInt .tryParse (x) != null ) {
640
- final v = BigInt .parse (x);
641
- return v >= min && v <= max;
642
642
} else {
643
643
return false ;
644
644
}
@@ -699,11 +699,6 @@ class FixedNatClass extends PrimitiveType<dynamic> {
699
699
} else if (x is int && x >= 0 ) {
700
700
final v = BigInt .from (x);
701
701
return v < max;
702
- } else if (x is String &&
703
- BigInt .tryParse (x) != null &&
704
- BigInt .parse (x) >= BigInt .zero) {
705
- final v = BigInt .parse (x);
706
- return v < max;
707
702
} else {
708
703
return false ;
709
704
}
@@ -904,7 +899,11 @@ class RecordClass extends ConstructType<Map> {
904
899
bool covariant (dynamic x) {
905
900
if (x is ! Map ) {
906
901
try {
907
- x = x.toJson ();
902
+ try {
903
+ x = x.toIDLSerializable ();
904
+ } on NoSuchMethodError {
905
+ x = x.toJson ();
906
+ }
908
907
} catch (e) {
909
908
return false ;
910
909
}
0 commit comments