kotlin - 使用对象映射器(在 kotlin 中)从 S3 读取没有键名的 json 文件(大约 180 MB)到数据类
问题描述
我在 s3 中的示例 json 如下所示:
{"380682":{"ids":[380682, 765894, 9875086]},"1995539":{"ids":[1995539, 234567, 987654]}}
我想将其映射到活动列表,其中:
data class Activities(
val key: String,
val values: List<String>
)
我的应用程序要求我只使用Object Mapper。
目前我正在这样做,但它需要的时间太长:
val activitiesList = mutableListOf<Activities>()
val response: Map<String, Map<String, List<String>>>
val reader: Reader = InputStreamReader(S3ObjectInputStream, StandardCharsets.UTF_8)
val jsonNode: JsonNode
reader.use { jsonNode = objectMapper.readTree(it) }
response = objectMapper.convertValue(jsonNode, object : TypeReference<Map<String, Map<String, List<String>>>>() {})
for ((key, value) in response) {
value.get("ids")?.let {
Activities(
key = key,
values = it)
}?.let { ActivitiesList.add(it) }
请建议一种更快,更清洁的方法来做到这一点......
解决方案
推荐阅读
- c++ - C++ 中的枚举和循环问题
- progress-bar - 无法将 tqdm 应用于 LDA 模型以跟踪训练进度
- vb.net - 图表销售订单统计
- python - Python:使用 bool() 选择哪些变量为 TRUE,然后使用这些值调用函数
- python - 如何合并两个数据框,以便行包含以左侧列中的元素开头的元素
- kubernetes - 运行旧 Kubernetes 版本的 OpenShift (Minishift)
- node.js - 来自执行环境的 AWS Lambda 凭证没有执行角色的权限
- swift - 放入 NSBox 子类不起作用
- python - 如何使用 python 绘制高斯 pdf 的轮廓?
- angular - 将 Angular 11 部署到 IIS 10 时出现错误 500.19