Skip to content

support for json to/from types.AttributeValue #3071

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

raduendv
Copy link
Contributor

@raduendv raduendv commented Apr 22, 2025

Implements the following functions for both feature/dynamodb/attributevalue and feature/dynamodbstreams/attributevalue to solve #2920 :

  • func UnmarshalListJSON(data []byte) ([]types.AttributeValue, error) {
  • func UnmarshalMapJSON(data []byte) (map[string]types.AttributeValue, error) {
  • func UnmarshalJSON(data []byte) (types.AttributeValue, error) {
  • func MarshalListJSON(in []types.AttributeValue) ([]byte, error) {
  • func MarshalMapJSON(in map[string]types.AttributeValue) ([]byte, error) {
  • func MarshalJSON(in types.AttributeValue) ([]byte, error) {

Each package makes use of the correct types package ( service/dynamodb/types for feature/dynamodb/attributevalue and service/dynamodbstreams/types for feature/dynamodbstreams/attributevalue )

@raduendv raduendv requested a review from a team as a code owner April 22, 2025 11:45
@raduendv raduendv force-pushed the feat-json-attribute-value branch from 26d9d88 to 85cdf5a Compare April 23, 2025 09:47
@raduendv raduendv force-pushed the feat-json-attribute-value branch from 85cdf5a to c87966c Compare April 23, 2025 12:08
Copy link
Contributor

@Madrigal Madrigal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly nitpicks, LGTM

if value != nil {
jtv, ok := value.(bool)
if !ok {
return fmt.Errorf("expected NullAttributeValue to be of type *bool, got %T instead", value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] shouldn't this be just bool?


shape, ok := value.([]interface{})
if !ok {
return fmt.Errorf("unexpected JSON type %v", value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] can we also include what type we expected, like fmt.Errorf("expected a JSON list, got type %T val %v")


for key, value := range shape {
var parsedVal types.AttributeValue
mapVar := parsedVal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] I don't think this intermediate variable is necessary

name: "&types.AttributeValueMemberM",
input: &types.AttributeValueMemberM{
Value: map[string]types.AttributeValue{
// we only use 1 key here because go does not guarantee key order and test will fail randomly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] We could also special case this and check against each key instead of just doing just string comparison, but this is fine as well

expected: `{"N":"123"}`,
},
{
name: "&types.AttributeValueMemberN 2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some special cases on DynamoDB for small or huge numbers that I'd also like to see tested, like numbers larger than math.MaxInt64. I'm sure current implementation would handle it, but it would give me peace of mind to have it explicitly tested

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

Successfully merging this pull request may close these issues.

3 participants