aws / aws-sdk-go-v2

AWS SDK for the Go programming language.
https://aws.github.io/aws-sdk-go-v2/docs/
Apache License 2.0
2.5k stars 602 forks source link

Use `encoding.TextMarshaler` and `encoding.TextUnmarshaler` in DynamoDB `attributevalue` marshalers/unmarshalers, if available #2596

Closed alexwennerberg closed 1 month ago

alexwennerberg commented 3 months ago

Describe the feature

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

AWS Go SDK V2 Module Versions Used

1.13.13

Go version used

1.22.1

RanVaknin commented 3 months ago

Adding to backlog.

github-actions[bot] commented 1 month ago

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.