I’ve got a webhook listener set up to catch v2.analytics.conversation.aggregate events for real-time dashboarding. The basic structure is clear enough, but the nested array of dataPoints is throwing a wrench in my Kotlin deserialization logic.
The event fires correctly, and I can see the raw JSON in the debug logs. The issue is that dataPoints contains a list of ConversationAggregateDataPoint objects, and each of those has a metrics map. I’m trying to extract the handled count for a specific queueId, but the keys in that map are dynamic based on the metric type.
Here’s the relevant snippet from the payload I’m receiving:
{
"id": "abc-123",
"dataPoints": [
{
"conversationId": "conv-xyz",
"metrics": {
"handled": {
"value": 1,
"unit": "count"
}
}
}
]
}
I’m using Jackson for JSON parsing. When I try to map this to a data class, it fails because metrics is a Map<String, Any> and I don’t know the schema of the inner object at compile time. I’ve tried using JsonNode to traverse it, but it’s getting messy.
I’ve tried the following:
- Using
ObjectMapper.readTree()to get aJsonNodeand then manually extracting values. It works but feels brittle. - Defining a generic
Metricsdata class withMap<String, MetricValue>, but Jackson complains about the nestedAnytype. - Checking the Swagger docs for
ConversationAggregateDataPoint, but the examples are sparse on complex nested scenarios.
Is there a cleaner way to handle this dynamic map structure without writing a custom deserializer for every possible metric type? I’d rather not hardcode the metric keys if possible. The event payload structure seems to imply that the map keys are the metric names, but the inner structure varies slightly depending on whether it’s a count, duration, or ratio.
I’m running this in a Spring Boot app, Kotlin 1.8, Jackson 2.14.