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
dynamodb/attributevalue: Support Text(Un)marshaler interfaces to avoid using special marshalers in simple cases #645
Labels
feature-request
A feature should be added or improved.
Comments
finnbear
changed the title
Support Text(Un)marshaler interfaces to avoid using special marshalers in simple cases
[dynamodb] Support Text(Un)marshaler interfaces to avoid using special marshalers in simple cases
Jul 15, 2020
jasdel
changed the title
[dynamodb] Support Text(Un)marshaler interfaces to avoid using special marshalers in simple cases
dynamodb/attributevalue: Support Text(Un)marshaler interfaces to avoid using special marshalers in simple cases
Nov 12, 2020
8 tasks
Closed
3 tasks
1 task
jasdel
added a commit
to jasdel/aws-sdk-go-v2
that referenced
this issue
Feb 17, 2022
Updates the `attributevalue` and `expression` package's handling of AttributeValue marshaling fixing several bugs in the packages. * Fixes aws#1569 `Inconsistent struct field name marshaled`. Fields will now be consistent with the EncoderOptions or DecoderOptions the Go struct was used with. Previously the Go struct fields would be cached with the first options used for the type. Causes subsequent usages to have the wrong field names if the encoding options used different TagKeys. * Fixes aws#645, aws#411 `Support more than string types for map keys`. Updates (un)marshaler to support number, bool, and types that implement encoding.Text(Un)Marshaler interfaces. * Fixes Support for expression Names with literal dots in name. Adds new function NameNoDotSplit to expression package. This function allows you to provide a literal expression Name containing dots. Also adds a new method to NameBuilder, AppendName, for joining multiple name path components together. Helpful for joining names with literal dots with subsequent object path fields. * Fixes bug with AttributeValue marshaler struct struct tag usage that caused TagKey to be ignored if the member had a struct tag with `dynamodbav` struct tag. Now both tags will be read as documented, with the TagKey struct tag options taking precedence.
jasdel
added a commit
that referenced
this issue
Feb 22, 2022
Updates the `attributevalue` and `expression` package's handling of AttributeValue marshaling fixing several bugs in the packages. * Fixes #1569 `Inconsistent struct field name marshaled`. Fields will now be consistent with the EncoderOptions or DecoderOptions the Go struct was used with. Previously the Go struct fields would be cached with the first options used for the type. Causes subsequent usages to have the wrong field names if the encoding options used different TagKeys. * Fixes #645, #411 `Support more than string types for map keys`. Updates (un)marshaler to support number, bool, and types that implement encoding.Text(Un)Marshaler interfaces. * Fixes Support for expression Names with literal dots in name. Adds new function NameNoDotSplit to expression package. This function allows you to provide a literal expression Name containing dots. Also adds a new method to NameBuilder, AppendName, for joining multiple name path components together. Helpful for joining names with literal dots with subsequent object path fields. * Fixes bug with AttributeValue marshaler struct struct tag usage that caused TagKey to be ignored if the member had a struct tag with `dynamodbav` struct tag. Now both tags will be read as documented, with the TagKey struct tag options taking precedence.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
In my project, I have several enumerators like
I have defined
MarshalText
andUnmarshalText
for each of them, so that they may be serialized as strings in JSON.I want to do the same in DynamoDB, but the only option is to create special DynamoDB marshalers and unmarshalers. The issue is that those special marshalers must be defined in the same package (due to Go's rules), and that is impossible in my project as the package that defines the enumerator type is shared with a client-side WebAssembly application that cannot afford to include an import of AWS SDK.
Describe the solution you'd like
If the struct tag
string
is used, and the type supports theText(Un)marshaler
interface, marshal/unmarshal using that interface.Describe alternatives you've considered
I've switched all my code to https://github.com/guregu/dynamo which supports this feature (even without a special struct tag). This one issue is the only reason I switched.
You could also add a new struct tag
text
in reference to TextMarshalerAdditional context
Full details in Go forum question: https://forum.golangbridge.org/t/implementing-custom-marshalers-unmarshalers-on-imported-types/19680
Issue initially filed under V1: aws/aws-sdk-go#3419
The text was updated successfully, but these errors were encountered: