【发布时间】:2020-12-22 05:49:51
【问题描述】:
我创建了一个包含Uint8List 成员的简单类:
import "package:json_annotation/json_annotation.dart";
part "openvpn.g.dart";
@JsonSerializable()
class OpenVPN extends VPN {
OpenVPN(Uint8List profile) {
this.profile = profile;
}
/...
Uint8List profile = null;
但是,当在其上运行构建运行程序以生成 json 序列化程序时,我得到:
Could not generate `fromJson` code for `profile`.
None of the provided `TypeHelper` instances support the defined type.
package:my_app/folder/openvpn.dart:19:13
╷
19 │ Uint8List profile = null;
│ ^^^^^^^
有没有办法为这种类型编写我自己的序列化程序?或者有没有更简单的方法? 我不想在 json 文件上有一个字符串,我想有实际的字节。这是一个小文件,因此在 json 中存储为字节数组是有意义的。
【问题讨论】: