Description
Acknowledgements
- I have searched (https://github.com/aws/aws-sdk/issues?q=is%3Aissue) for past instances of this issue
- I have verified all of my SDK modules are up-to-date (you can perform a bulk update with
go get -u github.com/aws/aws-sdk-go-v2/...
)
Describe the bug
When passing a struct with a custom type field, tagged with omitempty
, that implements the Marshaler interface to .MarshalMap(), the field should be omitted from the resulting map if the custom field's .MarshalDynamoDBAttributeValue()
implementation returns &types.AttributeValueMemberNULL{Value: true}, nil
.
Expected Behavior
omitempty should omit the custom field from the resulting map returned from .MarshalMap()
if the value is of type NULL
Current Behavior
.MarshalMap()
returns a map with a NULL field like: map[string]types.AttributeValue{"Val":(*types.AttributeValueMemberNULL)(0x1400021ea08)}
Reproduction Steps
import (
"testing"
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type OnlyNull struct{}
func (o OnlyNull) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) {
return &types.AttributeValueMemberNULL{Value: true}, nil
}
func TestMaybe(t *testing.T) {
t.Parallel()
type MyStruct struct {
Val OnlyNull `dynamodbav:",omitempty"`
}
// Test Fails
t.Run("omitted", func(t *testing.T) {
t.Parallel()
o := MyStruct{}
val, err := attributevalue.MarshalMap(o)
require.NoError(t, err)
assert.Empty(t, val)
})
}
Possible Solution
Either allow NULLs to be omitted by omitempty, or provide another type that implements types.AttributeValue
that is able to be omitted.
Additional Information/Context
No response
AWS Go SDK V2 Module Versions Used
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.14.10
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.4
github.com/aws/aws-sdk-go-v2 v1.30.3 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.3 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.27 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.15 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.22.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.17 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.15 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.58.3 // indirect
github.com/aws/smithy-go v1.20.3 // indirect
Compiler and Version used
go version go1.22.2 darwin/arm64
Operating System and version
MacOS Sonoma 14.5