Hi,
I have an AddressModel class with fromJson expecting a type of Map<String, dynamic> as few parameters are nullable. I store List<AddressModel> in another model and I have the TypeConverter for AddressModel as follows:
Now, the issue is that when the type conversion happens, it expects a List<Object> but finds a List<dynamic>. The workaround is to manually change List<Object> to List<dynamic> in the PostgresBinaryEncoder().convert() function from the postgres package as follows:
case PgDataType.jsonbArray:
{
if (input is List<dynamic>) // Here, List<Object> is changed to List<dynamic>
{
final objectsArray = input.map((v) => utf8.encode(json.encode(v)));
return writeListBytes<List<int>>(objectsArray, 3802, (item) => item.length + 1,
(writer, item) {
writer.writeUint8(1);
writer.write(item);
});
}
throw FormatException(
'Invalid type for parameter value. Expected: List<Object> Got: ${input.runtimeType}');
}
The code runs fine after his change and the data entry is added to the database. I am not sure if any changes can be made in AddressConverter code to resolve this issue.
Sounds like an issue with the postgres package. At least I don't have another idea right now so maybe just open a PR there to apply the fix with List<dynamic>
Hi, I have an
AddressModel
class withfromJson
expecting a type ofMap<String, dynamic>
as few parameters are nullable. I storeList<AddressModel>
in another model and I have the TypeConverter for AddressModel as follows:Now, the issue is that when the type conversion happens, it expects a
List<Object>
but finds aList<dynamic>
. The workaround is to manually changeList<Object>
toList<dynamic>
in thePostgresBinaryEncoder().convert()
function from the postgres package as follows:The code runs fine after his change and the data entry is added to the database. I am not sure if any changes can be made in
AddressConverter
code to resolve this issue.