Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize zero values #3243

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ClientOptionalTrait>()) {
Default.NoDefault
} else if (target.isDocumentShape || target.isTimestampShape) {
Default.NonZeroDefault(trait.toNode())
} else {
when (val value = trait.toNode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -378,10 +377,8 @@ class JsonSerializerGenerator(
)
}

with(serializerUtil) {
ignoreZeroValues(context.shape, context.valueExpression) {
serializeMemberValue(context, targetShape)
}
rustBlock("") {
serializeMemberValue(context, targetShape)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class XmlBindingTraitSerializerGenerator(

private val xmlIndex = XmlNameIndex.of(model)
private val rootNamespace = codegenContext.serviceShape.getTrait<XmlNamespaceTrait>()
private val util = SerializerUtil(model)

sealed class Ctx {
abstract val input: String
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions rust-runtime/aws-smithy-types/src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
Loading