commonMain.aws.sdk.kotlin.services.lexmodelbuildingservice.serde.GetImportOperationDeserializer.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.GetImportResponse
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.ImportStatus
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.LexModelBuildingException
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.MergeStrategy
import aws.sdk.kotlin.services.lexmodelbuildingservice.model.ResourceType
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 GetImportOperationDeserializer: HttpDeserializer.NonStreaming {
override fun deserialize(context: ExecutionContext, call: HttpCall, payload: ByteArray?): GetImportResponse {
val response = call.response
if (!response.status.isSuccess()) {
throwGetImportError(context, call, payload)
}
val builder = GetImportResponse.Builder()
if (payload != null) {
deserializeGetImportOperationBody(builder, payload)
}
builder.correctErrors()
return builder.build()
}
}
private fun throwGetImportError(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 deserializeGetImportOperationBody(builder: GetImportResponse.Builder, payload: ByteArray) {
val deserializer = JsonDeserializer(payload)
val CREATEDDATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("createdDate"))
val FAILUREREASON_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("failureReason"))
val IMPORTID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("importId"))
val IMPORTSTATUS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("importStatus"))
val MERGESTRATEGY_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("mergeStrategy"))
val NAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("name"))
val RESOURCETYPE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("resourceType"))
val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
field(CREATEDDATE_DESCRIPTOR)
field(FAILUREREASON_DESCRIPTOR)
field(IMPORTID_DESCRIPTOR)
field(IMPORTSTATUS_DESCRIPTOR)
field(MERGESTRATEGY_DESCRIPTOR)
field(NAME_DESCRIPTOR)
field(RESOURCETYPE_DESCRIPTOR)
}
deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
loop@while (true) {
when (findNextFieldIndex()) {
CREATEDDATE_DESCRIPTOR.index -> builder.createdDate = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
FAILUREREASON_DESCRIPTOR.index -> builder.failureReason =
deserializer.deserializeList(FAILUREREASON_DESCRIPTOR) {
val col0 = mutableListOf()
while (hasNextElement()) {
val el0 = if (nextHasValue()) { deserializeString() } else { deserializeNull(); continue }
col0.add(el0)
}
col0
}
IMPORTID_DESCRIPTOR.index -> builder.importId = deserializeString()
IMPORTSTATUS_DESCRIPTOR.index -> builder.importStatus = deserializeString().let { ImportStatus.fromValue(it) }
MERGESTRATEGY_DESCRIPTOR.index -> builder.mergeStrategy = deserializeString().let { MergeStrategy.fromValue(it) }
NAME_DESCRIPTOR.index -> builder.name = deserializeString()
RESOURCETYPE_DESCRIPTOR.index -> builder.resourceType = deserializeString().let { ResourceType.fromValue(it) }
null -> break@loop
else -> skipValue()
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy