@@ -55,7 +55,12 @@ Uint8List? tryToJson(CType type, dynamic value) {
5555 // obj may be a map, must be ignore.
5656 value is ! Map ) {
5757 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);
5964 } catch (e) {
6065 return null ;
6166 }
@@ -528,9 +533,7 @@ class NatClass extends PrimitiveType {
528533
529534 @override
530535 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 );
534537 }
535538
536539 @override
@@ -636,9 +639,6 @@ class FixedIntClass extends PrimitiveType {
636639 } else if (x is int ) {
637640 final v = BigInt .from (x);
638641 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;
642642 } else {
643643 return false ;
644644 }
@@ -699,11 +699,6 @@ class FixedNatClass extends PrimitiveType<dynamic> {
699699 } else if (x is int && x >= 0 ) {
700700 final v = BigInt .from (x);
701701 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;
707702 } else {
708703 return false ;
709704 }
@@ -904,7 +899,11 @@ class RecordClass extends ConstructType<Map> {
904899 bool covariant (dynamic x) {
905900 if (x is ! Map ) {
906901 try {
907- x = x.toJson ();
902+ try {
903+ x = x.toIDLSerializable ();
904+ } on NoSuchMethodError {
905+ x = x.toJson ();
906+ }
908907 } catch (e) {
909908 return false ;
910909 }
0 commit comments