medz / prisma-dart

Prisma Client Dart is an auto-generated type-safe ORM. It uses Prisma Engine as the data access layer and is as consistent as possible with the Prisma Client JS/TS APIs.
https://prisma.pub
BSD 3-Clause "New" or "Revised" License
436 stars 29 forks source link

toJson for JSON fields #371

Closed Spawin closed 3 weeks ago

Spawin commented 4 weeks ago

With #352 we have The method 'toJson' isn't defined for the class 'Object' when using JSON fields.

Example :

In prisma

model LoginHistory {
    id         BigInt           @id @default(autoincrement())
    // ...
    data       Json             @default("{}") @db.JsonB
    // ...
}

and in model.dart we have something like this

class LoginHistory {
  // ...
  final Object? data;
  // ...
  Map<String, dynamic> toJson() => {
        'id': id,
        // ...
        'data': data?.toJson(), // <= The method 'toJson' isn't defined for the class 'Object' 
        // ...
      };
}
medz commented 3 weeks ago

@Spawin Fixed in ORM 4.2.1 version