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

dynamodbattribute.Marshal() does not marshal json.Number to Numeric data type #3643

Closed
3 tasks done
MartinGall-EG opened this issue Nov 18, 2020 · 5 comments
Closed
3 tasks done
Assignees
Labels
bug This issue is a bug.

Comments

@MartinGall-EG
Copy link

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug

The deprecated dynamodbattribute.ConvertTo(...) function converts any values of the json.Number type to the numeric dynamodb data type N:

When migrating to the replacement dynamdbattribute.Marshal(...) the same numeric value is converted to the string dynamodb data type 'S:' instead of 'N:'

Version of AWS SDK for Go?
v1.35.20

  • get SDK version by printing the output of aws.SDKVersion in your code after importing "github.com/aws/aws-sdk-go/aws"

Version of Go (go version)?
1.15.2

To Reproduce (observed behavior)
Steps to reproduce the behavior (please share code or minimal repo)

import (
	"encoding/json"
	"fmt"
	"strings"

	"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
)

func main() {

	var raw interface{}
	decoder := json.NewDecoder(strings.NewReader(`{ "numeric": 9876543210123456 }`))
	decoder.UseNumber()
	decoder.Decode(&raw)

	ct, _ := dynamodbattribute.ConvertTo(raw)
	av, _ := dynamodbattribute.Marshal(raw)

	fmt.Println("*** ConvertTo ***")
	fmt.Println(ct)
	fmt.Println("*** dynamodbattribute.Marshal(...) ***")
	fmt.Println(av)
}

Expected behavior

I would expect dynamodbattribute.Marshal(...) to marshal values with a type of json.Number to N: as per the dynamodbattribute.ConvertTo(...) implementation i.e.

{
  M: {
    numeric: {
      N: "9876543210123456"
    }
  }
}

Additional context
Add any other context about the problem here.

@MartinGall-EG MartinGall-EG added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 18, 2020
@KaibaLopez
Copy link
Contributor

Hi @MartinGall-Emis ,
Yea, I can see the difference in the implementations... will look deeper into this and come with an update as soon as I figure something out.
Thanks for bringing this up to us.

@KaibaLopez KaibaLopez removed the needs-triage This issue or PR still needs to be triaged. label Nov 19, 2020
@KaibaLopez KaibaLopez self-assigned this Nov 19, 2020
@KaibaLopez
Copy link
Contributor

so, I've got an update on this.

Good news is, this will be something we work on.
Bad news is, it will only be for V2. Which is close to being officially released, at which point this version will be sunset-ed.

I'll be opening an issue to track this on the V2 issue queue. Feel free to comment on it if I missed something or if you want to add to the description.

@MartinGall-EG
Copy link
Author

@KaibaLopez Thank you so much for the update 👍 For the time being we can continue to work around this by using dynamodbattribute.ConvertTo(...) where required until the issue in aws-sdk-go-v2 is progressed.

@skotambkar
Copy link
Contributor

This issue has been fixed in https://github.com/aws/aws-sdk-go-v2, please use the v2 sdk .

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants