commonMain.aws.sdk.kotlin.services.lexmodelbuildingservice.serde.GetMigrationOperationDeserializer.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.GetMigrationResponse
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.LexModelBuildingException
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.Locale
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.MigrationAlert
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.MigrationStatus
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.MigrationStrategy
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 GetMigrationOperationDeserializer: HttpDeserializer.NonStreaming {
override fun deserialize(context: ExecutionContext, call: HttpCall, payload: ByteArray?): GetMigrationResponse {
val response = call.response
if (!response.status.isSuccess()) {
throwGetMigrationError(context, call, payload)
}
val builder = GetMigrationResponse.Builder()
if (payload != null) {
deserializeGetMigrationOperationBody(builder, payload)
}
builder.correctErrors()
return builder.build()
}
}
private fun throwGetMigrationError(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 deserializeGetMigrationOperationBody(builder: GetMigrationResponse.Builder, payload: ByteArray) {
val deserializer = JsonDeserializer(payload)
val ALERTS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("alerts"))
val MIGRATIONID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("migrationId"))
val MIGRATIONSTATUS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("migrationStatus"))
val MIGRATIONSTRATEGY_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("migrationStrategy"))
val MIGRATIONTIMESTAMP_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("migrationTimestamp"))
val V1BOTLOCALE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("v1BotLocale"))
val V1BOTNAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("v1BotName"))
val V1BOTVERSION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("v1BotVersion"))
val V2BOTID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("v2BotId"))
val V2BOTROLE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("v2BotRole"))
val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
field(ALERTS_DESCRIPTOR)
field(MIGRATIONID_DESCRIPTOR)
field(MIGRATIONSTATUS_DESCRIPTOR)
field(MIGRATIONSTRATEGY_DESCRIPTOR)
field(MIGRATIONTIMESTAMP_DESCRIPTOR)
field(V1BOTLOCALE_DESCRIPTOR)
field(V1BOTNAME_DESCRIPTOR)
field(V1BOTVERSION_DESCRIPTOR)
field(V2BOTID_DESCRIPTOR)
field(V2BOTROLE_DESCRIPTOR)
}
deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
loop@while (true) {
when (findNextFieldIndex()) {
ALERTS_DESCRIPTOR.index -> builder.alerts =
deserializer.deserializeList(ALERTS_DESCRIPTOR) {
val col0 = mutableListOf()
while (hasNextElement()) {
val el0 = if (nextHasValue()) { deserializeMigrationAlertDocument(deserializer) } else { deserializeNull(); continue }
col0.add(el0)
}
col0
}
MIGRATIONID_DESCRIPTOR.index -> builder.migrationId = deserializeString()
MIGRATIONSTATUS_DESCRIPTOR.index -> builder.migrationStatus = deserializeString().let { MigrationStatus.fromValue(it) }
MIGRATIONSTRATEGY_DESCRIPTOR.index -> builder.migrationStrategy = deserializeString().let { MigrationStrategy.fromValue(it) }
MIGRATIONTIMESTAMP_DESCRIPTOR.index -> builder.migrationTimestamp = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
V1BOTLOCALE_DESCRIPTOR.index -> builder.v1BotLocale = deserializeString().let { Locale.fromValue(it) }
V1BOTNAME_DESCRIPTOR.index -> builder.v1BotName = deserializeString()
V1BOTVERSION_DESCRIPTOR.index -> builder.v1BotVersion = deserializeString()
V2BOTID_DESCRIPTOR.index -> builder.v2BotId = deserializeString()
V2BOTROLE_DESCRIPTOR.index -> builder.v2BotRole = deserializeString()
null -> break@loop
else -> skipValue()
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy