When DynamoDB attributevalue marshals or unmarshals a struct, look to see if that struct implements encoding.TextMarshaler and encoding.TextUnmarshaler interfaces, and use them if available.
Use Case
When dynamodb's attributevalue marshals and unmarshals a custom type, it requires that you implement the attributevalue.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 marshaller
In 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 does
Proposed Solution
Update attributevalue's Marshaler and Unmarshaler to try, in addition to the attributevalue.Marshal interface, the encoding.Marshal interface, converting to and from an AttributeValueMemberS.
Other Information
No response
Acknowledgements
[X] I may be able to implement this feature request
This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
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 marshaller In 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 thatMarshalMap
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