You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could not generate fromJson code for map because of type ItemId.
Map keys must be one of: Object, dynamic, enum, String, BigInt, DateTime, int, Uri.
@JsonSerializable(explicitToJson:true)
classItem {
Item({requiredthis.id, requiredthis.map});
finalItemId id;
// Problem herefinalMap<ItemId, ItemId> map;
factoryItem.fromJson(Map<String, dynamic> json) =>_$ItemFromJson(json);
Map<String, dynamic> toJson() =>_$ItemToJson(this);
}
extension typeconstItemId(String id) {
factoryItemId.fromJson(String id) {
// Here could be some logic to parse the idreturnItemId(id);
}
StringtoJson() {
// Here could be some logic to convert the id to a stringreturn id;
}
}
Also, the case with explicitToJson: false could be tricky because in the ItemId class, toJson is just an extension method, and jsonEncode will simply unbox the String id value. This behavior is unexpected if the extension type has a toJson method.
The text was updated successfully, but these errors were encountered:
Codegenerator logs error:
Expected generated code
Also, the case with
explicitToJson: false
could be tricky because in theItemId
class,toJson
is just an extension method, andjsonEncode
will simply unbox theString id
value. This behavior is unexpected if the extension type has atoJson
method.The text was updated successfully, but these errors were encountered: