aws-sdk-go-v2 icon indicating copy to clipboard operation
aws-sdk-go-v2 copied to clipboard

Implement a custom type handler for big.Int in dynamodb/attributevalue encoder

Open rahul0tripathi opened this issue 2 years ago • 0 comments

Describe the feature

While encoding values using attributevalue.Marshal(), the big.Int type is treated as a simple struct but should be marshalled using Marshal

        x := new(big.Int).SetInt64(int64(23))
	fmt.Println(reflect.ValueOf(x).Elem().Kind())
        // output: struct

	av, _ := attributevalue.Marshal(x)

	fmt.Printf("%+v", av.(*types.AttributeValueMemberM).Value)
        //output: map[]

Use Case

To overcome this the big.Int type needs to be extended or a custom type needs to implemented. Having an in-built handler would save a lot of "I'm always frustrated when..."

Proposed Solution

Encoder should handle big.Int type separately just like time values and should be of type AttributeValueMemberS as the AttributeValueMemberN can only hold upto 38 significant digits

Other Information

No response

Acknowledgements

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

AWS Go SDK V2 Module Versions Used

// go.mod
require (
	github.com/aws/aws-sdk-go-v2 v1.16.6
	github.com/aws/aws-sdk-go-v2/config v1.15.11
	github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.9.5
	github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.4.11
	github.com/aws/aws-sdk-go-v2/service/athena v1.15.3
	github.com/aws/aws-sdk-go-v2/service/dynamodb v1.15.8
)

require (
	github.com/aws/aws-sdk-go-v2/credentials v1.12.6 // indirect
	github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.6 // indirect
	github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.13 // indirect
	github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.7 // indirect
	github.com/aws/aws-sdk-go-v2/internal/ini v1.3.13 // indirect
	github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.13.8 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.3 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.7 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.6 // indirect
	github.com/aws/aws-sdk-go-v2/service/sso v1.11.9 // indirect
	github.com/aws/aws-sdk-go-v2/service/sts v1.16.7 // indirect
	github.com/aws/smithy-go v1.12.0 // indirect
)

Go version used

go version go1.18.2 darwin/amd64

rahul0tripathi avatar Jul 05 '22 10:07 rahul0tripathi