Aws-sdk-go: dynamodbattribute.Marshal() does not marshal json.Number to Numeric data type

Created on 18 Nov 2020  路  3Comments  路  Source: aws/aws-sdk-go

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.

bug

Most helpful comment

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.

All 3 comments

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.

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.

@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.

Was this page helpful?
0 / 5 - 0 ratings