You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When marshaling the Go object with the embedded struct the name tag is ignored, so the fields from the embedded struct are always inlined. Which could cause unexpected behavior when we have the same field name in the object and in the embedded struct.
Expected Behavior
Marshaller should use the name tag and create a nested map attribute. The same way as the JSON marshaller does.
Reproduction Steps
package main
import (
"log"
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
dynamodbtypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
)
type MetaObject struct {
Org string `json:"org"`
}
type DataObject struct {
MetaObject `json:"metadata"`
Name string `json:"name"`
}
func main() {
encoder := attributevalue.NewEncoder(func(options *attributevalue.EncoderOptions) {
options.TagKey = "json"
})
encoded, _ := encoder.Encode(&DataObject{
MetaObject: MetaObject{Org: "org-1"},
Name: "name-1",
})
encodedMap := encoded.(*dynamodbtypes.AttributeValueMemberM)
if _, ok := encodedMap.Value["metadata"]; !ok {
log.Fatalf("metadata field is missing!")
}
}
Possible Solution
Create a new encoder option to disable default inlining behavior.
When collecting the fields in a struct, we skip over embedded fields
because by default they are just that: embedded.
However, if the embedded field itself carries a named tag, it is
not embedded during serialization, so consider this case.
fixesaws#2021
When collecting the fields in a struct, we skip over embedded fields
because by default they are just that: embedded.
However, if the embedded field itself carries a named tag, it is
not embedded during serialization, so consider this case.
fixes#2021
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.
Describe the bug
When marshaling the Go object with the embedded struct the
name
tag is ignored, so the fields from the embedded struct are always inlined. Which could cause unexpected behavior when we have the same field name in the object and in the embedded struct.Expected Behavior
Marshaller should use the
name
tag and create a nested map attribute. The same way as the JSON marshaller does.Reproduction Steps
Possible Solution
Create a new encoder option to disable default inlining behavior.
Additional Information/Context
No response
AWS Go SDK V2 Module Versions Used
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue@v1.10.11
github.com/aws/aws-sdk-go-v2/service/dynamodb@v1.18.2
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams@v1.14.2
Compiler and Version used
go version go1.19.5 darwin/arm64
Operating System and version
macOS Venture 13.1
The text was updated successfully, but these errors were encountered: