Parsing v2.analytics.conversation.aggregate JSON in Kotlin

We’ve got a Kotlin service sitting behind our Android app that consumes EventBridge events from Genesys Cloud. Specifically, we’re listening to v2.analytics.conversation.aggregate events to update local user stats. The webhook payload arrives, but the JSON structure is a bit deeper than I expected, and my data classes are failing to map correctly.

The root object contains a data array, but inside that, the conversation details are nested under conversationsitems. I’m trying to extract the id and type from the inner item. Here’s the relevant snippet of the payload I’m seeing in logs:

{
 "data": [
 {
 "conversations": {
 "items": [
 {
 "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
 "type": "webchat",
 "attributes": {
 "routing": {
 "queueId": "queue-123"
 }
 }
 }
 ]
 }
 }
 ]
}

I’m using Moshi for JSON parsing. My current EventPayload class looks like this:

@JsonClass(generateAdapter = true)
data class EventPayload(
 val data: List<ConversationData>
)

@JsonClass(generateAdapter = true)
data class ConversationData(
 val conversations: ConversationItems
)

@JsonClass(generateAdapter = true)
data class ConversationItems(
 val items: List<ConversationItem>
)

@JsonClass(generateAdapter = true)
data class ConversationItem(
 val id: String,
 val type: String,
 val attributes: Attributes
)

@JsonClass(generateAdapter = true)
data class Attributes(
 val routing: RoutingInfo
)

@JsonClass(generateAdapter = true)
data class RoutingInfo(
 val queueId: String
)

The issue is that attributes seems to be optional in some events, causing Moshi to throw a JsonDataException when it encounters a missing field. I’ve tried marking fields as nullable, but then I lose the type safety I need for the downstream logic. Is there a cleaner way to handle this nested structure without writing a custom JsonAdapter for every single event type? Or am I just missing a simple annotation? I’ve checked the docs, but they don’t cover the Kotlin side of things well enough for this specific nesting level.