My sample json in s3 looks like this :
{"380682":{"ids":[380682, 765894, 9875086]},"1995539":{"ids":[1995539, 234567, 987654]}}
I want to map it to List of Activities where:
data class Activities(
val key: String,
val values: List<String>
)
My application requires me to use Object Mapper only.
Currently I am doing it this way but it takes way too long:
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) }
Please suggest a faster and cleaner way to do this...