Skip to content

How to serialize the mongodb '_id' ? #261

Closed
@Yaxian

Description

@Yaxian

Hi,
I have a problem to serialize mongodb document, because of the _id field.
For example,
account collection is

{ _id: 1, name: 'test'}

account.dart file is like below:

import 'package:json_annotation/json_annotation.dart';
part 'account.g.dart';

class Account extends Object with _$AccountSerializerMixin {
  // final String id;
  @JsonKey(name: '_id')
  String _id;
  String name;
  

  Account(
      this._id,
      this.name,
);
  factory Account.fromJson(Map<String, dynamic> json) =>
      _$AccountFromJson(json);
}

it will fail to run flutter packages pub run build_runner watch. Any idea about the problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions