commonMain.aws.sdk.kotlin.services.lexruntimeservice.serde.PutSessionOperationSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lexruntimeservice-jvm Show documentation
Show all versions of lexruntimeservice-jvm Show documentation
The AWS Kotlin client for Lex Runtime Service
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!
package aws.sdk.kotlin.services.lexruntimeservice.serde
import aws.sdk.kotlin.services.lexruntimeservice.model.ActiveContext
import aws.sdk.kotlin.services.lexruntimeservice.model.DialogAction
import aws.sdk.kotlin.services.lexruntimeservice.model.IntentSummary
import aws.sdk.kotlin.services.lexruntimeservice.model.PutSessionRequest
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpMethod
import aws.smithy.kotlin.runtime.http.operation.HttpSerializer
import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder
import aws.smithy.kotlin.runtime.http.request.headers
import aws.smithy.kotlin.runtime.http.request.url
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.json.JsonSerializer
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.text.encoding.PercentEncoding
internal class PutSessionOperationSerializer: HttpSerializer.NonStreaming {
override fun serialize(context: ExecutionContext, input: PutSessionRequest): HttpRequestBuilder {
val builder = HttpRequestBuilder()
builder.method = HttpMethod.POST
builder.url {
requireNotNull(input.botName) { "botName is bound to the URI and must not be null" }
requireNotNull(input.botAlias) { "botAlias is bound to the URI and must not be null" }
requireNotNull(input.userId) { "userId is bound to the URI and must not be null" }
path.encodedSegments {
add(PercentEncoding.Path.encode("bot"))
add(PercentEncoding.SmithyLabel.encode(input.botName))
add(PercentEncoding.Path.encode("alias"))
add(PercentEncoding.SmithyLabel.encode(input.botAlias))
add(PercentEncoding.Path.encode("user"))
add(PercentEncoding.SmithyLabel.encode(input.userId))
add(PercentEncoding.Path.encode("session"))
}
}
builder.headers {
if (input.accept?.isNotEmpty() == true) append("Accept", input.accept)
}
val payload = serializePutSessionOperationBody(context, input)
builder.body = HttpBody.fromBytes(payload)
if (builder.body !is HttpBody.Empty) {
builder.headers.setMissing("Content-Type", "application/json")
}
return builder
}
}
private fun serializePutSessionOperationBody(context: ExecutionContext, input: PutSessionRequest): ByteArray {
val serializer = JsonSerializer()
val ACTIVECONTEXTS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("activeContexts"))
val DIALOGACTION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("dialogAction"))
val RECENTINTENTSUMMARYVIEW_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("recentIntentSummaryView"))
val SESSIONATTRIBUTES_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Map, JsonSerialName("sessionAttributes"))
val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
field(ACTIVECONTEXTS_DESCRIPTOR)
field(DIALOGACTION_DESCRIPTOR)
field(RECENTINTENTSUMMARYVIEW_DESCRIPTOR)
field(SESSIONATTRIBUTES_DESCRIPTOR)
}
serializer.serializeStruct(OBJ_DESCRIPTOR) {
if (input.activeContexts != null) {
listField(ACTIVECONTEXTS_DESCRIPTOR) {
for (el0 in input.activeContexts) {
serializeSdkSerializable(asSdkSerializable(el0, ::serializeActiveContextDocument))
}
}
}
input.dialogAction?.let { field(DIALOGACTION_DESCRIPTOR, it, ::serializeDialogActionDocument) }
if (input.recentIntentSummaryView != null) {
listField(RECENTINTENTSUMMARYVIEW_DESCRIPTOR) {
for (el0 in input.recentIntentSummaryView) {
serializeSdkSerializable(asSdkSerializable(el0, ::serializeIntentSummaryDocument))
}
}
}
if (input.sessionAttributes != null) {
mapField(SESSIONATTRIBUTES_DESCRIPTOR) {
input.sessionAttributes.forEach { (key, value) ->
entry(key, value)
}
}
}
}
return serializer.toByteArray()
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy