Use encoding.TextMarshaler
and encoding.TextUnmarshaler
in DynamoDB attributevalue
marshalers/unmarshalers, if available
#2596
Labels
feature-request
A feature should be added or improved.
p2
This is a standard priority issue
queued
This issues is on the AWS team's backlog
Describe the feature
When DynamoDB
attributevalue
marshals or unmarshals a struct, look to see if that struct implementsencoding.TextMarshaler
andencoding.TextUnmarshaler
interfaces, and use them if available.Use Case
When dynamodb's
attributevalue
marshals and unmarshals a custom type, it requires that you implement theattributevalue.Marshaler
interface on that type. This is somewhat awkward and requires dynamodb-specific code on a type that may have nothing to do with dynamodb, or it requires building some sort of wrapper marshallerIn many cases, all that we want to do is unmarshal or marshal a custom type as a dynamodb string (ie, a subfield of a struct that
MarshalMap
is being called upon, representing a DynamoDB record), thus we should be able to implement encoding/text's interfaces on our custom type interface that looks to see if a type has implemented this interface and, if so, use it to marshal (or unmarshal) to/from a dynamodb type using that interface, much like the https://cs.opensource.google/go/go/+/refs/tags/go1.22.1:src/encoding/json/encode.go;l=36 encoding/json package doesProposed Solution
Update attributevalue's Marshaler and Unmarshaler to try, in addition to the
attributevalue.Marshal
interface, theencoding.Marshal
interface, converting to and from anAttributeValueMemberS
.Other Information
No response
Acknowledgements
AWS Go SDK V2 Module Versions Used
1.13.13
Go version used
1.22.1
The text was updated successfully, but these errors were encountered: