All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.aws.sdk.kotlin.services.lexmodelbuildingservice.serde.GetIntentOperationDeserializer.kt Maven / Gradle / Ivy

There is a newer version: 1.4.2
Show newest version
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!

package aws.sdk.kotlin.services.lexmodelbuildingservice.serde

import aws.sdk.kotlin.services.lexmodelbuildingservice.model.CodeHook
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.FollowUpPrompt
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.FulfillmentActivity
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.GetIntentResponse
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.InputContext
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.KendraConfiguration
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.LexModelBuildingException
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.OutputContext
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.Prompt
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.Slot
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.Statement
import aws.smithy.kotlin.runtime.awsprotocol.json.RestJsonErrorDeserializer
import aws.smithy.kotlin.runtime.awsprotocol.setAseErrorMetadata
import aws.smithy.kotlin.runtime.awsprotocol.withPayload
import aws.smithy.kotlin.runtime.http.HttpCall
import aws.smithy.kotlin.runtime.http.isSuccess
import aws.smithy.kotlin.runtime.http.operation.HttpDeserializer
import aws.smithy.kotlin.runtime.operation.ExecutionContext
import aws.smithy.kotlin.runtime.serde.SdkFieldDescriptor
import aws.smithy.kotlin.runtime.serde.SdkObjectDescriptor
import aws.smithy.kotlin.runtime.serde.SerialKind
import aws.smithy.kotlin.runtime.serde.asSdkSerializable
import aws.smithy.kotlin.runtime.serde.deserializeList
import aws.smithy.kotlin.runtime.serde.deserializeMap
import aws.smithy.kotlin.runtime.serde.deserializeStruct
import aws.smithy.kotlin.runtime.serde.field
import aws.smithy.kotlin.runtime.serde.json.JsonDeserializer
import aws.smithy.kotlin.runtime.serde.json.JsonSerialName
import aws.smithy.kotlin.runtime.serde.serializeList
import aws.smithy.kotlin.runtime.serde.serializeMap
import aws.smithy.kotlin.runtime.serde.serializeStruct
import aws.smithy.kotlin.runtime.time.Instant
import aws.smithy.kotlin.runtime.time.TimestampFormat
import kotlin.collections.mutableListOf


internal class GetIntentOperationDeserializer: HttpDeserializer.NonStreaming {

    override fun deserialize(context: ExecutionContext, call: HttpCall, payload: ByteArray?): GetIntentResponse {
        val response = call.response
        if (!response.status.isSuccess()) {
            throwGetIntentError(context, call, payload)
        }
        val builder = GetIntentResponse.Builder()

        if (payload != null) {
            deserializeGetIntentOperationBody(builder, payload)
        }
        builder.correctErrors()
        return builder.build()
    }
}

private fun throwGetIntentError(context: ExecutionContext, call: HttpCall, payload: ByteArray?): kotlin.Nothing {
    val wrappedResponse = call.response.withPayload(payload)
    val wrappedCall = call.copy(response = wrappedResponse)

    val errorDetails = try {
        RestJsonErrorDeserializer.deserialize(call.response.headers, payload)
    } catch (ex: Exception) {
        throw LexModelBuildingException("Failed to parse response as 'restJson1' error", ex).also {
            setAseErrorMetadata(it, wrappedCall.response, null)
        }
    }

    val ex = when(errorDetails.code) {
        "NotFoundException" -> NotFoundExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "LimitExceededException" -> LimitExceededExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "BadRequestException" -> BadRequestExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "InternalFailureException" -> InternalFailureExceptionDeserializer().deserialize(context, wrappedCall, payload)
        else -> LexModelBuildingException(errorDetails.message)
    }

    setAseErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

private fun deserializeGetIntentOperationBody(builder: GetIntentResponse.Builder, payload: ByteArray) {
    val deserializer = JsonDeserializer(payload)
    val CHECKSUM_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("checksum"))
    val CONCLUSIONSTATEMENT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("conclusionStatement"))
    val CONFIRMATIONPROMPT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("confirmationPrompt"))
    val CREATEDDATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("createdDate"))
    val DESCRIPTION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("description"))
    val DIALOGCODEHOOK_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("dialogCodeHook"))
    val FOLLOWUPPROMPT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("followUpPrompt"))
    val FULFILLMENTACTIVITY_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("fulfillmentActivity"))
    val INPUTCONTEXTS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("inputContexts"))
    val KENDRACONFIGURATION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("kendraConfiguration"))
    val LASTUPDATEDDATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("lastUpdatedDate"))
    val NAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("name"))
    val OUTPUTCONTEXTS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("outputContexts"))
    val PARENTINTENTSIGNATURE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("parentIntentSignature"))
    val REJECTIONSTATEMENT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("rejectionStatement"))
    val SAMPLEUTTERANCES_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("sampleUtterances"))
    val SLOTS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("slots"))
    val VERSION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("version"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(CHECKSUM_DESCRIPTOR)
        field(CONCLUSIONSTATEMENT_DESCRIPTOR)
        field(CONFIRMATIONPROMPT_DESCRIPTOR)
        field(CREATEDDATE_DESCRIPTOR)
        field(DESCRIPTION_DESCRIPTOR)
        field(DIALOGCODEHOOK_DESCRIPTOR)
        field(FOLLOWUPPROMPT_DESCRIPTOR)
        field(FULFILLMENTACTIVITY_DESCRIPTOR)
        field(INPUTCONTEXTS_DESCRIPTOR)
        field(KENDRACONFIGURATION_DESCRIPTOR)
        field(LASTUPDATEDDATE_DESCRIPTOR)
        field(NAME_DESCRIPTOR)
        field(OUTPUTCONTEXTS_DESCRIPTOR)
        field(PARENTINTENTSIGNATURE_DESCRIPTOR)
        field(REJECTIONSTATEMENT_DESCRIPTOR)
        field(SAMPLEUTTERANCES_DESCRIPTOR)
        field(SLOTS_DESCRIPTOR)
        field(VERSION_DESCRIPTOR)
    }

    deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
        loop@while (true) {
            when (findNextFieldIndex()) {
                CHECKSUM_DESCRIPTOR.index -> builder.checksum = deserializeString()
                CONCLUSIONSTATEMENT_DESCRIPTOR.index -> builder.conclusionStatement = deserializeStatementDocument(deserializer)
                CONFIRMATIONPROMPT_DESCRIPTOR.index -> builder.confirmationPrompt = deserializePromptDocument(deserializer)
                CREATEDDATE_DESCRIPTOR.index -> builder.createdDate = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
                DESCRIPTION_DESCRIPTOR.index -> builder.description = deserializeString()
                DIALOGCODEHOOK_DESCRIPTOR.index -> builder.dialogCodeHook = deserializeCodeHookDocument(deserializer)
                FOLLOWUPPROMPT_DESCRIPTOR.index -> builder.followUpPrompt = deserializeFollowUpPromptDocument(deserializer)
                FULFILLMENTACTIVITY_DESCRIPTOR.index -> builder.fulfillmentActivity = deserializeFulfillmentActivityDocument(deserializer)
                INPUTCONTEXTS_DESCRIPTOR.index -> builder.inputContexts =
                    deserializer.deserializeList(INPUTCONTEXTS_DESCRIPTOR) {
                        val col0 = mutableListOf()
                        while (hasNextElement()) {
                            val el0 = if (nextHasValue()) { deserializeInputContextDocument(deserializer) } else { deserializeNull(); continue }
                            col0.add(el0)
                        }
                        col0
                    }
                KENDRACONFIGURATION_DESCRIPTOR.index -> builder.kendraConfiguration = deserializeKendraConfigurationDocument(deserializer)
                LASTUPDATEDDATE_DESCRIPTOR.index -> builder.lastUpdatedDate = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
                NAME_DESCRIPTOR.index -> builder.name = deserializeString()
                OUTPUTCONTEXTS_DESCRIPTOR.index -> builder.outputContexts =
                    deserializer.deserializeList(OUTPUTCONTEXTS_DESCRIPTOR) {
                        val col0 = mutableListOf()
                        while (hasNextElement()) {
                            val el0 = if (nextHasValue()) { deserializeOutputContextDocument(deserializer) } else { deserializeNull(); continue }
                            col0.add(el0)
                        }
                        col0
                    }
                PARENTINTENTSIGNATURE_DESCRIPTOR.index -> builder.parentIntentSignature = deserializeString()
                REJECTIONSTATEMENT_DESCRIPTOR.index -> builder.rejectionStatement = deserializeStatementDocument(deserializer)
                SAMPLEUTTERANCES_DESCRIPTOR.index -> builder.sampleUtterances =
                    deserializer.deserializeList(SAMPLEUTTERANCES_DESCRIPTOR) {
                        val col0 = mutableListOf()
                        while (hasNextElement()) {
                            val el0 = if (nextHasValue()) { deserializeString() } else { deserializeNull(); continue }
                            col0.add(el0)
                        }
                        col0
                    }
                SLOTS_DESCRIPTOR.index -> builder.slots =
                    deserializer.deserializeList(SLOTS_DESCRIPTOR) {
                        val col0 = mutableListOf()
                        while (hasNextElement()) {
                            val el0 = if (nextHasValue()) { deserializeSlotDocument(deserializer) } else { deserializeNull(); continue }
                            col0.add(el0)
                        }
                        col0
                    }
                VERSION_DESCRIPTOR.index -> builder.version = deserializeString()
                null -> break@loop
                else -> skipValue()
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy