diff --git a/feature/dynamodb/attributevalue/decode.go b/feature/dynamodb/attributevalue/decode.go index 8a92f8979a3..f865671cec1 100644 --- a/feature/dynamodb/attributevalue/decode.go +++ b/feature/dynamodb/attributevalue/decode.go @@ -114,6 +114,13 @@ func UnmarshalListOfMaps(l []map[string]types.AttributeValue, out interface{}) e // DecoderOptions is a collection of options to configure how the decoder // unmarshalls the value. type DecoderOptions struct { + // States that the encoding/json struct tags should be supported. + // if a `dynamodbav` struct tag is also provided the encoding/json + // tag will be ignored. + // + // Enabled by default. + SupportJSONTags bool + // Support other custom struct tag keys, such as `yaml`, `json`, or `toml`. // Note that values provided with a custom TagKey must also be supported // by the (un)marshalers in this package. @@ -136,7 +143,10 @@ type Decoder struct { // NewDecoder creates a new Decoder with default configuration. Use // the `opts` functional options to override the default configuration. func NewDecoder(optFns ...func(*DecoderOptions)) *Decoder { - var options DecoderOptions + var options = DecoderOptions{ + SupportJSONTags: true, + } + for _, fn := range optFns { fn(&options) } @@ -509,7 +519,8 @@ func (d *Decoder) decodeMap(avMap map[string]types.AttributeValue, v reflect.Val } } else if v.Kind() == reflect.Struct { fields := unionStructFields(v.Type(), structFieldOptions{ - TagKey: d.options.TagKey, + TagKey: d.options.TagKey, + SupportJSONTags: true, }) for k, av := range avMap { if f, ok := fields.FieldByName(k); ok { diff --git a/feature/dynamodb/attributevalue/encode.go b/feature/dynamodb/attributevalue/encode.go index 56e1db53d2b..1090ba6a782 100644 --- a/feature/dynamodb/attributevalue/encode.go +++ b/feature/dynamodb/attributevalue/encode.go @@ -212,6 +212,13 @@ func MarshalList(in interface{}) ([]types.AttributeValue, error) { // EncoderOptions is a collection of options shared between marshaling // and unmarshaling type EncoderOptions struct { + // States that the encoding/json struct tags should be supported. + // if a `dynamodbav` struct tag is also provided the encoding/json + // tag will be ignored. + // + // Enabled by default. + SupportJSONTags bool + // Support other custom struct tag keys, such as `yaml`, `json`, or `toml`. // Note that values provided with a custom TagKey must also be supported // by the (un)marshalers in this package. @@ -241,7 +248,8 @@ type Encoder struct { // the `opts` functional options to override the default configuration. func NewEncoder(optFns ...func(*EncoderOptions)) *Encoder { options := EncoderOptions{ - NullEmptySets: true, + NullEmptySets: true, + SupportJSONTags: true, } for _, fn := range optFns { fn(&options) diff --git a/feature/dynamodb/attributevalue/field.go b/feature/dynamodb/attributevalue/field.go index 7abd3479a96..2f9f85cb681 100644 --- a/feature/dynamodb/attributevalue/field.go +++ b/feature/dynamodb/attributevalue/field.go @@ -34,6 +34,13 @@ func buildField(pIdx []int, i int, sf reflect.StructField, fieldTag tag) field { } type structFieldOptions struct { + // States that the encoding/json struct tags should be supported. + // if a `dynamodbav` struct tag is also provided the encoding/json + // tag will be ignored. + // + // Enabled by default. + SupportJSONTags bool + // Support other custom struct tag keys, such as `yaml`, `json`, or `toml`. // Note that values provided with a custom TagKey must also be supported // by the (un)marshalers in this package. @@ -107,6 +114,8 @@ func enumFields(t reflect.Type, opts structFieldOptions) []field { // Because MarshalOptions.TagKey must be explicitly set. if opts.TagKey != "" && fieldTag == (tag{}) { fieldTag.parseStructTag(opts.TagKey, sf.Tag) + } else if opts.SupportJSONTags && fieldTag == (tag{}) { + fieldTag.parseStructTag("json", sf.Tag) } if fieldTag.Ignore {