带颤振的红石映射器
Redstone mapper with flutter
我想使用 redstone mapper 将 Json 解码为对象。
但是 flutter 不支持镜像,因此我无法使用 bootstrapMapper();
以正常方式初始化映射器
所以我查了一下,不得不用staticBootstrapMapper(...)
/**
* initialize the mapper system.
*
* This function provides a mapper implementation that
* uses data generated by the redstone_mapper's transformer,
* instead of relying on the mirrors API.
*
*/
void staticBootstrapMapper(Map<Type, TypeInfo> types) {
_staticTypeInfo = types;
configure(_getOrCreateMapper, _createValidator);
}
我不知道应该在 Map<Type, TypeInfo> types
的地图中放入什么。
假设我想使用 ObjectData 将 json 数据转换为该对象。
但是我必须如何使用这种初始化方法? 遗憾的是我没有找到如何使用这种静态 bootstrap 管理器的示例。
class ObjectData {
@Field()
@NotEmpty()
DataType dateType; // might be a User object
@Field()
@NotEmpty()
String id;
@Field()
@NotEmpty()
List<String> versions;
}
如上文评论所述,Flutter 不支持镜像。
您可能想尝试不依赖镜像的替代包:
在这两个(和其他)中,json_serializable
看起来是最容易上手的,但可能没有那么多功能。
我想使用 redstone mapper 将 Json 解码为对象。
但是 flutter 不支持镜像,因此我无法使用 bootstrapMapper();
所以我查了一下,不得不用staticBootstrapMapper(...)
/**
* initialize the mapper system.
*
* This function provides a mapper implementation that
* uses data generated by the redstone_mapper's transformer,
* instead of relying on the mirrors API.
*
*/
void staticBootstrapMapper(Map<Type, TypeInfo> types) {
_staticTypeInfo = types;
configure(_getOrCreateMapper, _createValidator);
}
我不知道应该在 Map<Type, TypeInfo> types
的地图中放入什么。
假设我想使用 ObjectData 将 json 数据转换为该对象。
但是我必须如何使用这种初始化方法? 遗憾的是我没有找到如何使用这种静态 bootstrap 管理器的示例。
class ObjectData {
@Field()
@NotEmpty()
DataType dateType; // might be a User object
@Field()
@NotEmpty()
String id;
@Field()
@NotEmpty()
List<String> versions;
}
如上文评论所述,Flutter 不支持镜像。
您可能想尝试不依赖镜像的替代包:
在这两个(和其他)中,json_serializable
看起来是最容易上手的,但可能没有那么多功能。