mat*_*edi 5 json dart json-serializable
我必须序列化 json 才能从 Enum 创建特定的子类,该子类是包含抽象类目标的一个类的属性
class Test {
Outcome outcome;
TestType type;
}
abstract class Outcome {
String attribute;
}
class PackageOutcome extends Outcome {
String packageAttribute;
}
class FlexibilityOutcome extends Outcome {
String flexibilityAttribute;
}
Run Code Online (Sandbox Code Playgroud)
Outcome 没有序列化 json 的工厂方法,但 PackageOutcome 和 FlexibilityOutcome 有。
在工厂方法中,Test.toJson()如果我有特定类型的 Enum TestType,我会创建 PackageOutcome,如果我有另一种类型,我会创建FlexibilityOutcome为测试结果。
你可以用 json_serialized 来做到这一点吗?有一些教程解释了如何做到这一点?
| 归档时间: |
|
| 查看次数: |
220 次 |
| 最近记录: |