如何解决似乎您的 Enum 类字段缺少注释 - MobX dart
我的应用中有一个名为学生的 MobX 商店,就像这样
学生模型
@jsonSerializable
class Student = _Student with _$Student;
@jsonSerializable
abstract class _Student with Store {
_Student(this.studentName,this.age,this.joinDate,this.color,this.marks);
@observable
String studentName;
@observable
int age;
@observable
DateTime joinDate;
@observable
String color;
@observable
ObservableList<Mark> marks;
}
并像这样标记商店
标记模型
@jsonSerializable
class Mark = _Mark with _$Mark;
@jsonSerializable
abstract class _Mark with Store {
_Mark(this.name,this.amount);
@observable
String name;
@observable
double amount;
}
我的学生商店看起来像这样
学生商店
@jsonSerializable
@Json(allowCircularReferences: 1)
class StudentStore = _StudentStore with _$StudentStore;
@jsonSerializable
abstract class _StudentStore with Store {
@observable
ObservableList<Student> students = ObservableList<Student>();
@action
void addStudent(String studentName,int age,DateTime joinDate,String color) {
final newStudent = Budget(studentName,age,joinDate,color,ObservableList<Mark>());
students.add(newStudent);
final listJson = JsonMapper.serialize(students);
print(listJson);
}
}
我正在尝试使用 shared_preference 将此学生商店保存在本地存储中,因此我需要将整个商店转换为 json,以便将其保存为 json。
正如您在 Students store 中在 addStudent
操作中看到的那样,我很想使用 JSON and serialization
但是我收到了这样的错误。我不知道这里有什么问题,也许我使用了错误的术语。
════════ Exception caught by gesture ═══════════════════════════════════════════
The following _MissingEnumValuesErrorImpl was thrown while handling a gesture:
It seems your Enum class field is missing annotation:
@JsonProperty(enumValues: Student.values)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。