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?
Oh, I resolved it:
@JsonKey(name: '_id')
String id;
Account(
this.id,
this.name,
)
Most helpful comment
Oh, I resolved it: