in codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/RestJson1.kt [35:61]
override fun renderSerializeHttpBody(
ctx: ProtocolGenerator.GenerationContext,
op: OperationShape,
writer: KotlinWriter
) {
super.renderSerializeHttpBody(ctx, op, writer)
val resolver = getProtocolHttpBindingResolver(ctx.model, ctx.service)
if (!resolver.hasHttpBody(op)) return
// restjson1 has some different semantics and expectations around empty structures bound via @httpPayload trait
// * empty structures get serialized to `{}`
// see: https://github.com/awslabs/smithy/pull/924
val requestBindings = resolver.requestBindings(op)
val httpPayload = requestBindings.firstOrNull { it.location == HttpBinding.Location.PAYLOAD }
if (httpPayload != null) {
// explicit payload member as the sole payload
val memberName = httpPayload.member.defaultName()
val target = ctx.model.expectShape(httpPayload.member.target)
if (target is StructureShape) {
writer.withBlock("if (input.#L == null) {", "}", memberName) {
addImport(RuntimeTypes.Http.ByteArrayContent)
write("builder.body = #T(#S.encodeToByteArray())", RuntimeTypes.Http.ByteArrayContent, "{}")
}
}
}
}