Add support for omitting attribute values returned by custom Marshaler implementations #1429
Labels
feature-request
A feature should be added or improved.
l
Effort estimation: large
p3
This is a minor priority issue
queued
This issues is on the AWS team's backlog
Is your feature request related to a problem? Please describe.
We are working on a project that uses a custom type to represent UUIDs. This type, which extends
github.com/google/uuid
, stores the UUID in memory as a[16]byte
array, but we’ve added a customMarshal
andUnmarshal
implementation that marshals/unmarshals it to a string UUID representation.We were hoping to allow the service writing rows to the DynamoDB table to omit an
id
field when the UUID is nil (i.e. 16 zero bytes). However, we’ve discovered that this is not possible to do when using a type that implementsgithub.com/aws/aws-sdk-go-v2/service/dynamodb/dynamodbattribute.Marshaler
. We’re hoping that this could be added in some way.Describe the solution you'd like
There’s not a huge preference as to how this is implemented, either the following suggestion or one of the alternatives will be find. Depending on the stability of the API, an ideal solution would be to return double
nil
fromMarshal.MarshalDynamoDBAttributeValue
to indicate that no attribute value should be marshalled out. Example:Describe alternatives you've considered
A few other suggestions for this approach:
omitempty
in the struct tag for custom types. So using the example above, ifu
isNilUUID
, then the function will return atypes.AttributeValueMemberS
with an empty string. Since the field that has this type also has theomitempty
option in the struct tag, the value won’t be marshalled out to the database.Additional context
We’re using “aws-sdk-go-v2” version 1.5.0 with Go 1.16.6
The text was updated successfully, but these errors were encountered: