commonMain.aws.sdk.kotlin.services.lexmodelbuildingservice.serde.PutBotOperationDeserializer.kt Maven / Gradle / Ivy
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!
package aws.sdk.kotlin.services.lexmodelbuildingservice.serde
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.Intent
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.LexModelBuildingException
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.Locale
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.Prompt
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.PutBotResponse
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.Statement
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.Status
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.Tag
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 PutBotOperationDeserializer: HttpDeserializer.NonStreaming {
override fun deserialize(context: ExecutionContext, call: HttpCall, payload: ByteArray?): PutBotResponse {
val response = call.response
if (!response.status.isSuccess()) {
throwPutBotError(context, call, payload)
}
val builder = PutBotResponse.Builder()
if (payload != null) {
deserializePutBotOperationBody(builder, payload)
}
builder.correctErrors()
return builder.build()
}
}
private fun throwPutBotError(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) {
"ConflictException" -> ConflictExceptionDeserializer().deserialize(context, wrappedCall, payload)
"LimitExceededException" -> LimitExceededExceptionDeserializer().deserialize(context, wrappedCall, payload)
"BadRequestException" -> BadRequestExceptionDeserializer().deserialize(context, wrappedCall, payload)
"PreconditionFailedException" -> PreconditionFailedExceptionDeserializer().deserialize(context, wrappedCall, payload)
"InternalFailureException" -> InternalFailureExceptionDeserializer().deserialize(context, wrappedCall, payload)
else -> LexModelBuildingException(errorDetails.message)
}
setAseErrorMetadata(ex, wrappedResponse, errorDetails)
throw ex
}
private fun deserializePutBotOperationBody(builder: PutBotResponse.Builder, payload: ByteArray) {
val deserializer = JsonDeserializer(payload)
val ABORTSTATEMENT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("abortStatement"))
val CHECKSUM_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("checksum"))
val CHILDDIRECTED_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Boolean, JsonSerialName("childDirected"))
val CLARIFICATIONPROMPT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("clarificationPrompt"))
val CREATEVERSION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Boolean, JsonSerialName("createVersion"))
val CREATEDDATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("createdDate"))
val DESCRIPTION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("description"))
val DETECTSENTIMENT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Boolean, JsonSerialName("detectSentiment"))
val ENABLEMODELIMPROVEMENTS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Boolean, JsonSerialName("enableModelImprovements"))
val FAILUREREASON_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("failureReason"))
val IDLESESSIONTTLINSECONDS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Integer, JsonSerialName("idleSessionTTLInSeconds"))
val INTENTS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("intents"))
val LASTUPDATEDDATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("lastUpdatedDate"))
val LOCALE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("locale"))
val NAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("name"))
val NLUINTENTCONFIDENCETHRESHOLD_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Double, JsonSerialName("nluIntentConfidenceThreshold"))
val STATUS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("status"))
val TAGS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("tags"))
val VERSION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("version"))
val VOICEID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("voiceId"))
val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
field(ABORTSTATEMENT_DESCRIPTOR)
field(CHECKSUM_DESCRIPTOR)
field(CHILDDIRECTED_DESCRIPTOR)
field(CLARIFICATIONPROMPT_DESCRIPTOR)
field(CREATEVERSION_DESCRIPTOR)
field(CREATEDDATE_DESCRIPTOR)
field(DESCRIPTION_DESCRIPTOR)
field(DETECTSENTIMENT_DESCRIPTOR)
field(ENABLEMODELIMPROVEMENTS_DESCRIPTOR)
field(FAILUREREASON_DESCRIPTOR)
field(IDLESESSIONTTLINSECONDS_DESCRIPTOR)
field(INTENTS_DESCRIPTOR)
field(LASTUPDATEDDATE_DESCRIPTOR)
field(LOCALE_DESCRIPTOR)
field(NAME_DESCRIPTOR)
field(NLUINTENTCONFIDENCETHRESHOLD_DESCRIPTOR)
field(STATUS_DESCRIPTOR)
field(TAGS_DESCRIPTOR)
field(VERSION_DESCRIPTOR)
field(VOICEID_DESCRIPTOR)
}
deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
loop@while (true) {
when (findNextFieldIndex()) {
ABORTSTATEMENT_DESCRIPTOR.index -> builder.abortStatement = deserializeStatementDocument(deserializer)
CHECKSUM_DESCRIPTOR.index -> builder.checksum = deserializeString()
CHILDDIRECTED_DESCRIPTOR.index -> builder.childDirected = deserializeBoolean()
CLARIFICATIONPROMPT_DESCRIPTOR.index -> builder.clarificationPrompt = deserializePromptDocument(deserializer)
CREATEVERSION_DESCRIPTOR.index -> builder.createVersion = deserializeBoolean()
CREATEDDATE_DESCRIPTOR.index -> builder.createdDate = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
DESCRIPTION_DESCRIPTOR.index -> builder.description = deserializeString()
DETECTSENTIMENT_DESCRIPTOR.index -> builder.detectSentiment = deserializeBoolean()
ENABLEMODELIMPROVEMENTS_DESCRIPTOR.index -> builder.enableModelImprovements = deserializeBoolean()
FAILUREREASON_DESCRIPTOR.index -> builder.failureReason = deserializeString()
IDLESESSIONTTLINSECONDS_DESCRIPTOR.index -> builder.idleSessionTtlInSeconds = deserializeInt()
INTENTS_DESCRIPTOR.index -> builder.intents =
deserializer.deserializeList(INTENTS_DESCRIPTOR) {
val col0 = mutableListOf()
while (hasNextElement()) {
val el0 = if (nextHasValue()) { deserializeIntentDocument(deserializer) } else { deserializeNull(); continue }
col0.add(el0)
}
col0
}
LASTUPDATEDDATE_DESCRIPTOR.index -> builder.lastUpdatedDate = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
LOCALE_DESCRIPTOR.index -> builder.locale = deserializeString().let { Locale.fromValue(it) }
NAME_DESCRIPTOR.index -> builder.name = deserializeString()
NLUINTENTCONFIDENCETHRESHOLD_DESCRIPTOR.index -> builder.nluIntentConfidenceThreshold = deserializeDouble()
STATUS_DESCRIPTOR.index -> builder.status = deserializeString().let { Status.fromValue(it) }
TAGS_DESCRIPTOR.index -> builder.tags =
deserializer.deserializeList(TAGS_DESCRIPTOR) {
val col0 = mutableListOf()
while (hasNextElement()) {
val el0 = if (nextHasValue()) { deserializeTagDocument(deserializer) } else { deserializeNull(); continue }
col0.add(el0)
}
col0
}
VERSION_DESCRIPTOR.index -> builder.version = deserializeString()
VOICEID_DESCRIPTOR.index -> builder.voiceId = deserializeString()
null -> break@loop
else -> skipValue()
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy