{"record":{"id":"0a0077cd47125b39","repo":"quarkusio/quarkus","slug":"unexpected-index-index","errorCode":null,"errorMessage":"Unexpected index $index","messagePattern":"Unexpected index \\$index","errorType":"exception","errorClass":"SerializationException","httpStatus":null,"severity":"error","filePath":"extensions/resteasy-reactive/rest-kotlin-serialization/runtime/src/main/kotlin/io/quarkus/resteasy/reactive/kotlin/serialization/runtime/ViolationReportSerializer.kt","lineNumber":48,"sourceCode":"    override fun deserialize(decoder: Decoder): ViolationReport {\n        return decoder.decodeStructure(descriptor) {\n            var title: String? = null\n            var status: Int? = null\n            var violations: List<ViolationReport.Violation> = emptyList()\n\n            loop@ while (true) {\n                when (val index = decodeElementIndex(descriptor)) {\n                    DECODE_DONE -> break@loop\n                    0 -> title = decodeStringElement(descriptor, 0)\n                    1 -> status = decodeIntElement(descriptor, 1)\n                    2 ->\n                        violations =\n                            decodeSerializableElement(\n                                descriptor,\n                                2,\n                                ListSerializer(ViolationReportViolationSerializer),\n                            )\n                    else -> throw SerializationException(\"Unexpected index $index\")\n                }\n            }\n\n            ViolationReport(\n                requireNotNull(title),\n                status?.let { Response.Status.fromStatusCode(it) },\n                violations,\n            )\n        }\n    }\n\n    override fun serialize(encoder: Encoder, value: ViolationReport) {\n        encoder.encodeStructure(descriptor) {\n            encodeStringElement(descriptor, 0, value.title)\n            encodeIntElement(descriptor, 1, value.status)\n            encodeSerializableElement(\n                descriptor,\n                2,","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/resteasy-reactive/rest-kotlin-serialization/runtime/src/main/kotlin/io/quarkus/resteasy/reactive/kotlin/serialization/runtime/ViolationReportSerializer.kt#L30-L66","documentation":"ViolationReportSerializer is a kotlinx.serialization KSerializer for the RESTClassic/Reactive ViolationReport. Its decodeStructure loop only accepts element indices 0 (title), 1 (status), 2 (violations); any other index from decodeElementIndex throws SerializationException(\"Unexpected index $index\"). This guards against malformed or unknown JSON fields when the decoder is not lenient.","triggerScenarios":"Deserializing a JSON body into ViolationReport that produces an element index outside 0..2 — typically caused by extra/unknown keys with a strict descriptor or a mismatched JSON shape.","commonSituations":"Clients posting constraint-violation reports with extra fields; version mismatch between producer and consumer of the violation report format; custom JSON with unexpected ordering/keys under non-ignoring JSON configuration.","solutions":["Ensure the JSON payload only contains title, status, and violations keys","Configure kotlinx.serialization Json with ignoreUnknownKeys = true when decoding untrusted payloads","Regenerate/align the payload with the server's ViolationReport format (check Quarkus version for format changes)","Write a custom serializer allowing unknown keys if the format must evolve"],"exampleFix":"// before\nval json = Json\n// after\nval json = Json { ignoreUnknownKeys = true }","handlingStrategy":"try-catch","validationCode":"// Validate payload keys before deserialization\nval allowed = setOf(\"title\", \"status\", \"violations\")\nrequire(jsonObject.keys().all { it in allowed }) { \"Unknown keys in ViolationReport JSON\" }","typeGuard":null,"tryCatchPattern":"try {\n    Json.decodeFromString(ViolationReportSerializer, body)\n} catch (e: SerializationException) {\n    // retry decode with Json { ignoreUnknownKeys = true }\n    Json { ignoreUnknownKeys = true }.decodeFromString(ViolationReportSerializer, body)\n}","preventionTips":["Enable ignoreUnknownKeys = true for external payloads","Keep producer/consumer violation-report schemas in sync","Add contract tests for the violation report JSON shape"],"tags":["kotlin","kotlinx-serialization","deserialization","validation","resteasy-reactive"],"backgroundTag":"unexpected-field-deserialization","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}