
commonMain.aws.sdk.kotlin.services.mgn.transform.FinalizeCutoverOperationDeserializer.kt Maven / Gradle / Ivy
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!
package aws.sdk.kotlin.services.mgn.transform
import aws.sdk.kotlin.runtime.http.setAseErrorMetadata
import aws.sdk.kotlin.runtime.http.withPayload
import aws.sdk.kotlin.runtime.protocol.json.RestJsonErrorDeserializer
import aws.sdk.kotlin.services.mgn.model.DataReplicationInfo
import aws.sdk.kotlin.services.mgn.model.FinalizeCutoverResponse
import aws.sdk.kotlin.services.mgn.model.LaunchedInstance
import aws.sdk.kotlin.services.mgn.model.LifeCycle
import aws.sdk.kotlin.services.mgn.model.MgnException
import aws.sdk.kotlin.services.mgn.model.ReplicationType
import aws.sdk.kotlin.services.mgn.model.SourceProperties
import aws.smithy.kotlin.runtime.client.ExecutionContext
import aws.smithy.kotlin.runtime.http.isSuccess
import aws.smithy.kotlin.runtime.http.operation.HttpDeserialize
import aws.smithy.kotlin.runtime.http.readAll
import aws.smithy.kotlin.runtime.http.response.HttpResponse
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
internal class FinalizeCutoverOperationDeserializer: HttpDeserialize {
override suspend fun deserialize(context: ExecutionContext, response: HttpResponse): FinalizeCutoverResponse {
if (!response.status.isSuccess()) {
throwFinalizeCutoverError(context, response)
}
val builder = FinalizeCutoverResponse.Builder()
val payload = response.body.readAll()
if (payload != null) {
deserializeFinalizeCutoverOperationBody(builder, payload)
}
return builder.build()
}
}
private suspend fun throwFinalizeCutoverError(context: ExecutionContext, response: HttpResponse): kotlin.Nothing {
val payload = response.body.readAll()
val wrappedResponse = response.withPayload(payload)
val errorDetails = try {
RestJsonErrorDeserializer.deserialize(response.headers, payload)
} catch (ex: Exception) {
throw MgnException("Failed to parse response as 'restJson1' error", ex).also {
setAseErrorMetadata(it, wrappedResponse, null)
}
}
val ex = when(errorDetails.code) {
"ConflictException" -> ConflictExceptionDeserializer().deserialize(context, wrappedResponse)
"ResourceNotFoundException" -> ResourceNotFoundExceptionDeserializer().deserialize(context, wrappedResponse)
"UninitializedAccountException" -> UninitializedAccountExceptionDeserializer().deserialize(context, wrappedResponse)
"ValidationException" -> ValidationExceptionDeserializer().deserialize(context, wrappedResponse)
else -> MgnException(errorDetails.message)
}
setAseErrorMetadata(ex, wrappedResponse, errorDetails)
throw ex
}
private fun deserializeFinalizeCutoverOperationBody(builder: FinalizeCutoverResponse.Builder, payload: ByteArray) {
val deserializer = JsonDeserializer(payload)
val ARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("arn"))
val DATAREPLICATIONINFO_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("dataReplicationInfo"))
val ISARCHIVED_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Boolean, JsonSerialName("isArchived"))
val LAUNCHEDINSTANCE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("launchedInstance"))
val LIFECYCLE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("lifeCycle"))
val REPLICATIONTYPE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("replicationType"))
val SOURCEPROPERTIES_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("sourceProperties"))
val SOURCESERVERID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("sourceServerID"))
val TAGS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Map, JsonSerialName("tags"))
val VCENTERCLIENTID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("vcenterClientID"))
val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
field(ARN_DESCRIPTOR)
field(DATAREPLICATIONINFO_DESCRIPTOR)
field(ISARCHIVED_DESCRIPTOR)
field(LAUNCHEDINSTANCE_DESCRIPTOR)
field(LIFECYCLE_DESCRIPTOR)
field(REPLICATIONTYPE_DESCRIPTOR)
field(SOURCEPROPERTIES_DESCRIPTOR)
field(SOURCESERVERID_DESCRIPTOR)
field(TAGS_DESCRIPTOR)
field(VCENTERCLIENTID_DESCRIPTOR)
}
deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
loop@while (true) {
when (findNextFieldIndex()) {
ARN_DESCRIPTOR.index -> builder.arn = deserializeString()
DATAREPLICATIONINFO_DESCRIPTOR.index -> builder.dataReplicationInfo = deserializeDataReplicationInfoDocument(deserializer)
ISARCHIVED_DESCRIPTOR.index -> builder.isArchived = deserializeBoolean()
LAUNCHEDINSTANCE_DESCRIPTOR.index -> builder.launchedInstance = deserializeLaunchedInstanceDocument(deserializer)
LIFECYCLE_DESCRIPTOR.index -> builder.lifeCycle = deserializeLifeCycleDocument(deserializer)
REPLICATIONTYPE_DESCRIPTOR.index -> builder.replicationType = deserializeString().let { ReplicationType.fromValue(it) }
SOURCEPROPERTIES_DESCRIPTOR.index -> builder.sourceProperties = deserializeSourcePropertiesDocument(deserializer)
SOURCESERVERID_DESCRIPTOR.index -> builder.sourceServerId = deserializeString()
TAGS_DESCRIPTOR.index -> builder.tags =
deserializer.deserializeMap(TAGS_DESCRIPTOR) {
val map0 = mutableMapOf()
while (hasNextEntry()) {
val k0 = key()
val v0 = if (nextHasValue()) { deserializeString() } else { deserializeNull(); continue }
map0[k0] = v0
}
map0
}
VCENTERCLIENTID_DESCRIPTOR.index -> builder.vcenterClientId = deserializeString()
null -> break@loop
else -> skipValue()
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy