Skip to content

Commit d8c0f17

Browse files
committed
🐛 Use an explicit serialization method rather than toJson
1 parent 69cd117 commit d8c0f17

File tree

1 file changed

+11
-2
lines changed
  • packages/agent_dart_base/lib/candid

1 file changed

+11
-2
lines changed

packages/agent_dart_base/lib/candid/idl.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -904,7 +909,11 @@ class RecordClass extends ConstructType<Map> {
904909
bool covariant(dynamic x) {
905910
if (x is! Map) {
906911
try {
907-
x = x.toJson();
912+
try {
913+
x = x.toIDLSerializable();
914+
} on NoSuchMethodError {
915+
x = x.toJson();
916+
}
908917
} catch (e) {
909918
return false;
910919
}

0 commit comments

Comments
 (0)