diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt index af74c80d9f6..f3cca65c927 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt @@ -38,6 +38,7 @@ import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.TimestampShape import software.amazon.smithy.model.shapes.UnionShape +import software.amazon.smithy.model.traits.ClientOptionalTrait import software.amazon.smithy.model.traits.DefaultTrait import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.ErrorTrait @@ -269,7 +270,9 @@ open class SymbolVisitor( override fun memberShape(shape: MemberShape): Symbol { val target = model.expectShape(shape.target) val defaultValue = shape.getMemberTrait(model, DefaultTrait::class.java).orNull()?.let { trait -> - if (target.isDocumentShape || target.isTimestampShape) { + if (shape.hasTrait()) { + Default.NoDefault + } else if (target.isDocumentShape || target.isTimestampShape) { Default.NonZeroDefault(trait.toNode()) } else { when (val value = trait.toNode()) { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt index 981706b5665..609d32c3f80 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt @@ -178,7 +178,6 @@ class JsonSerializerGenerator( "JsonValueWriter" to RuntimeType.smithyJson(runtimeConfig).resolve("serialize::JsonValueWriter"), "ByteSlab" to RuntimeType.ByteSlab, ) - private val serializerUtil = SerializerUtil(model) /** * Reusable structure serializer implementation that can be used to generate serializing code for @@ -378,10 +377,8 @@ class JsonSerializerGenerator( ) } - with(serializerUtil) { - ignoreZeroValues(context.shape, context.valueExpression) { - serializeMemberValue(context, targetShape) - } + rustBlock("") { + serializeMemberValue(context, targetShape) } } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt index 23c8bbb4fb8..14c313f674f 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt @@ -96,7 +96,6 @@ abstract class QuerySerializerGenerator(private val codegenContext: CodegenConte private val serializerError = runtimeConfig.serializationError() private val smithyTypes = RuntimeType.smithyTypes(runtimeConfig) private val smithyQuery = RuntimeType.smithyQuery(runtimeConfig) - private val serdeUtil = SerializerUtil(model) private val protocolFunctions = ProtocolFunctions(codegenContext) private val codegenScope = arrayOf( "String" to RuntimeType.String, @@ -208,10 +207,8 @@ abstract class QuerySerializerGenerator(private val codegenContext: CodegenConte } } } else { - with(serdeUtil) { - ignoreZeroValues(context.shape, context.valueExpression) { - serializeMemberValue(context, targetShape) - } + rustBlock("") { + serializeMemberValue(context, targetShape) } } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/SerializerUtil.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/SerializerUtil.kt deleted file mode 100644 index 27293e43039..00000000000 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/SerializerUtil.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize - -import software.amazon.smithy.model.Model -import software.amazon.smithy.model.shapes.MemberShape -import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock - -class SerializerUtil(private val model: Model) { - fun RustWriter.ignoreZeroValues(shape: MemberShape, value: ValueExpression, inner: Writable) { - // Required shapes should always be serialized - // See https://github.com/smithy-lang/smithy-rs/issues/230 and https://github.com/aws/aws-sdk-go-v2/pull/1129 - if ( - shape.isRequired || - // Zero values are always serialized in lists and collections, this only applies to structures - model.expectShape(shape.container) !is StructureShape - ) { - rustBlock("") { - inner(this) - } - } else { - this.ifNotDefault(model.expectShape(shape.target), value) { inner(this) } - } - } -} diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt index fc4f0198387..68e31a533a8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt @@ -73,7 +73,6 @@ class XmlBindingTraitSerializerGenerator( private val xmlIndex = XmlNameIndex.of(model) private val rootNamespace = codegenContext.serviceShape.getTrait() - private val util = SerializerUtil(model) sealed class Ctx { abstract val input: String @@ -517,15 +516,8 @@ class XmlBindingTraitSerializerGenerator( inner(Ctx.updateInput(ctx, tmp)) } } else { - with(util) { - val valueExpression = if (ctx.input.startsWith("&")) { - ValueExpression.Reference(ctx.input) - } else { - ValueExpression.Value(ctx.input) - } - ignoreZeroValues(member, valueExpression) { - inner(ctx) - } + rustBlock("") { + inner(ctx) } } } diff --git a/rust-runtime/aws-smithy-types/src/blob.rs b/rust-runtime/aws-smithy-types/src/blob.rs index ab7ae30d3c5..1087b6d930c 100644 --- a/rust-runtime/aws-smithy-types/src/blob.rs +++ b/rust-runtime/aws-smithy-types/src/blob.rs @@ -31,6 +31,14 @@ impl AsRef<[u8]> for Blob { } } +impl Default for Blob { + fn default() -> Self { + Blob { + inner: Vec::new() + } + } +} + #[cfg(all(aws_sdk_unstable, feature = "serde-serialize"))] mod serde_serialize { use super::*;