Skip to content

When using JSONB with BlobColumn nullable, it doesn't accept null #3441

@wtomezaki

Description

@wtomezaki

I'm using the new JSONB column, but I want it to be nullable, and it seems that the converter doesn't accept "null"

Also, I'm using the develop branch files which contain the fix #3436

type 'Null' is not a subtype of type 'Uint8List' of 'fromDb'
#0      _DefaultJsonConverter.fromSql (package:drift/src/runtime/types/converters.dart:379:15)
@j.JsonSerializable()
class PropertyArea {
  final String propertyAreaId;
  final GeoJson? mapBoundaries;
  final double area;
  final int areaType;
  final String propertyId;
  final DateTime createdAt;

  PropertyArea(
    this.propertyAreaId,
    this.mapBoundaries,
    this.area,
    this.areaType,
    this.propertyId,
    this.createdAt,
  );

  factory PropertyArea.fromJson(Map<String, dynamic> json) => _$PropertyAreaFromJson(json);

  Map<String, dynamic> toJson() => _$PropertyAreaToJson(this);

  static JsonTypeConverter2<PropertyArea?, Uint8List?, Object?> binaryConverter = TypeConverter.jsonb(
    fromJson: (json) => PropertyArea.fromJson(json as Map<String, Object?>),
    toJson: (pref) => pref?.toJson(),
  );
}
class Properties extends Table {
  TextColumn get propertyId => text()();
  BlobColumn get propertyArea => blob().nullable().map(PropertyArea.binaryConverter)();

  @override
  Set<Column> get primaryKey => {propertyId};
}

Even if I try exactly like the documentation using:

  static JsonTypeConverter2<PropertyArea, Uint8List, Object?> binaryConverter = TypeConverter.jsonb(
    fromJson: (json) => PropertyArea.fromJson(json as Map<String, Object?>),
    toJson: (pref) => pref.toJson(),
  );

I get this error in the drift generated file:

The argument type 'JsonTypeConverter2<PropertyArea, Uint8List, Object?>' can't be assigned to the parameter type 'JsonTypeConverter2<PropertyArea, Uint8List, Object>'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions