我在 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) }
请建议一种更快,更清洁的方法来做到这一点......