Skip to content
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: allow registration of custom type marshal/unmarshal functions #2042

Closed
1 of 2 tasks
ztison opened this issue Feb 27, 2023 · 6 comments
Closed
1 of 2 tasks
Assignees
Labels
feature-request A feature should be added or improved. p3 This is a minor priority issue wontfix We have determined that we will not resolve the issue.

Comments

@ztison
Copy link

ztison commented Feb 27, 2023

Describe the feature

As a DynamoDB user, I want to be able to register custom marshaler/unmarshaler functions.

Use Case

  • I want to have common API types not coupled with the repository layer. So I don't want to implement MarshalDynamoDBAttributeValue and UnmarshalDynamoDBAttributeValue functions with dependency on AttributeValue in my high-level code.

  • I want to implement custom marshaler/unmarshaler for types that I don't own. It can be required because of data masking or to omit empty values.

Proposed Solution

func (e *Encoder) RegisterMarshaller(t reflect.Type, f func(interface{}) (types.AttributeValue, error)) error
func (d *Decoder) RegisterUnmarshaller(t reflect.Type, f func(types.AttributeValue) (interface{}, error)) error
type Foo string

func StringMarshaller(value interface{}) (types.AttributeValue, error) {
	if foo, ok := value.(Foo); ok {
		return &types.AttributeValueMemberS{Value: string(foo)}, nil
	}
	return nil, fmt.Errorf("type error")
}

var foo = "foo"
enc.RegisterMarshaller(reflect.TypeOf(foo), StringMarshaller)

Other Information

Based on customer marshaler/unmarshaler for json

Rejected Alternatives

API without exposing reflect:

func (e *Encoder) RegisterFunc(f interface{})
func (d *Decoder) RegisterFunc(f interface{})

API based on generics:

func (e *Encoder)  Register[T any](f func(T) (types.AttributeValue, error)) { ... }
func (d *Decoder)  Register[T any](f func(types.AttributeValue) (T, error)) { ... }

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS Go SDK V2 Module Versions Used

github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue@v1.10.14
github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression@v1.4.39
github.com/aws/aws-sdk-go-v2/service/dynamodb@v1.18.4
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams@v1.14.4

Go version used

go version go1.19.5 darwin/arm64

@ztison ztison added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Feb 27, 2023
@aajtodd aajtodd removed the needs-triage This issue or PR still needs to be triaged. label Feb 28, 2023
@RanVaknin RanVaknin added the p3 This is a minor priority issue label Mar 16, 2023
@raulvc
Copy link

raulvc commented May 8, 2023

so.. turns out this still isn't a thing, could you point me to a fork/custom implementation of an attributevalue encoder/decoder that allows me to register a uuid type?

@ztison
Copy link
Author

ztison commented May 9, 2023

Just closed PR exists https://github.com/aws/aws-sdk-go-v2/pull/2060/files

@RanVaknin RanVaknin self-assigned this Feb 15, 2024
@RanVaknin RanVaknin added the wontfix We have determined that we will not resolve the issue. label Feb 15, 2024
@RanVaknin
Copy link
Contributor

Hi all, thank you for your patience. At this point in time, there is no plan to implement this. We are aware that there discussions happening on the standard library level, and we want to see how this is developing before taking any action on it from our side.

I hope we can revisit this sooner than later.
Thanks,
Ran~

@RanVaknin RanVaknin closed this as not planned Won't fix, can't repro, duplicate, stale Feb 15, 2024
Copy link

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.

@ashwinrs
Copy link

ashwinrs commented Sep 19, 2024

+1 to @ztison proposal on how to ideally expose custom marshaler/unmarshaller. The existing interface makes the code extremely verbose and complex.

For example, we use go generics when interacting with DynamoDB. DynamoDB does not handle structpb.Struct well. So the way we now have to handle it is, iterate over every field in all the structs to check if its of type structpb.Struct and then do the custom handling. It would be a lot cleaner with the approach @ztison proposed.

@austince
Copy link

I work with @ztison, we were ultimately forced to fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. p3 This is a minor priority issue wontfix We have determined that we will not resolve the issue.
Projects
None yet
Development

No branches or pull requests

6 participants