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

commonMain.aws.sdk.kotlin.services.finspacedata.serde.GetUserOperationDeserializer.kt Maven / Gradle / Ivy

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

package aws.sdk.kotlin.services.finspacedata.serde

import aws.sdk.kotlin.services.finspacedata.model.ApiAccess
import aws.sdk.kotlin.services.finspacedata.model.FinspaceDataException
import aws.sdk.kotlin.services.finspacedata.model.GetUserResponse
import aws.sdk.kotlin.services.finspacedata.model.UserStatus
import aws.sdk.kotlin.services.finspacedata.model.UserType
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


internal class GetUserOperationDeserializer: HttpDeserializer.NonStreaming {

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

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

private fun throwGetUserError(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 FinspaceDataException("Failed to parse response as 'restJson1' error", ex).also {
            setAseErrorMetadata(it, wrappedCall.response, null)
        }
    }

    val ex = when(errorDetails.code) {
        "AccessDeniedException" -> AccessDeniedExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "ValidationException" -> ValidationExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "InternalServerException" -> InternalServerExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "ResourceNotFoundException" -> ResourceNotFoundExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "ThrottlingException" -> ThrottlingExceptionDeserializer().deserialize(context, wrappedCall, payload)
        else -> FinspaceDataException(errorDetails.message)
    }

    setAseErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

private fun deserializeGetUserOperationBody(builder: GetUserResponse.Builder, payload: ByteArray) {
    val deserializer = JsonDeserializer(payload)
    val APIACCESS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("apiAccess"))
    val APIACCESSPRINCIPALARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("apiAccessPrincipalArn"))
    val CREATETIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("createTime"))
    val EMAILADDRESS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("emailAddress"))
    val FIRSTNAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("firstName"))
    val LASTDISABLEDTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("lastDisabledTime"))
    val LASTENABLEDTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("lastEnabledTime"))
    val LASTLOGINTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("lastLoginTime"))
    val LASTMODIFIEDTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("lastModifiedTime"))
    val LASTNAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("lastName"))
    val STATUS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("status"))
    val TYPE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("type"))
    val USERID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("userId"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(APIACCESS_DESCRIPTOR)
        field(APIACCESSPRINCIPALARN_DESCRIPTOR)
        field(CREATETIME_DESCRIPTOR)
        field(EMAILADDRESS_DESCRIPTOR)
        field(FIRSTNAME_DESCRIPTOR)
        field(LASTDISABLEDTIME_DESCRIPTOR)
        field(LASTENABLEDTIME_DESCRIPTOR)
        field(LASTLOGINTIME_DESCRIPTOR)
        field(LASTMODIFIEDTIME_DESCRIPTOR)
        field(LASTNAME_DESCRIPTOR)
        field(STATUS_DESCRIPTOR)
        field(TYPE_DESCRIPTOR)
        field(USERID_DESCRIPTOR)
    }

    deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
        loop@while (true) {
            when (findNextFieldIndex()) {
                APIACCESS_DESCRIPTOR.index -> builder.apiAccess = deserializeString().let { ApiAccess.fromValue(it) }
                APIACCESSPRINCIPALARN_DESCRIPTOR.index -> builder.apiAccessPrincipalArn = deserializeString()
                CREATETIME_DESCRIPTOR.index -> builder.createTime = deserializeLong()
                EMAILADDRESS_DESCRIPTOR.index -> builder.emailAddress = deserializeString()
                FIRSTNAME_DESCRIPTOR.index -> builder.firstName = deserializeString()
                LASTDISABLEDTIME_DESCRIPTOR.index -> builder.lastDisabledTime = deserializeLong()
                LASTENABLEDTIME_DESCRIPTOR.index -> builder.lastEnabledTime = deserializeLong()
                LASTLOGINTIME_DESCRIPTOR.index -> builder.lastLoginTime = deserializeLong()
                LASTMODIFIEDTIME_DESCRIPTOR.index -> builder.lastModifiedTime = deserializeLong()
                LASTNAME_DESCRIPTOR.index -> builder.lastName = deserializeString()
                STATUS_DESCRIPTOR.index -> builder.status = deserializeString().let { UserStatus.fromValue(it) }
                TYPE_DESCRIPTOR.index -> builder.type = deserializeString().let { UserType.fromValue(it) }
                USERID_DESCRIPTOR.index -> builder.userId = deserializeString()
                null -> break@loop
                else -> skipValue()
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy