File tree Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,40 @@ func TestMarshalItemAsymmetric(t *testing.T) {
152152 }
153153}
154154
155+ func TestIssue247 (t * testing.T ) {
156+ // https: //github.com/guregu/dynamo/issues/247
157+ type ServerResponse struct {
158+ EmbeddedID int
159+ }
160+ type TestAddition struct {
161+ ServerResponse
162+ }
163+ type TestItem struct {
164+ ID int `dynamo:"id,hash" json:"id"`
165+ Name string `dynamo:"name,range" json:"name"`
166+ Addition TestAddition `dynamo:"addition,omitempty"`
167+ }
168+ x := TestItem {ID : 1 , Name : "test" }
169+ item , err := MarshalItem (x )
170+ if err != nil {
171+ t .Fatal (err )
172+ }
173+ _ , ok := item ["addition" ]
174+ if ok {
175+ t .Error ("should be omitted" )
176+ }
177+
178+ x .Addition .EmbeddedID = 123
179+ item , err = MarshalItem (x )
180+ if err != nil {
181+ t .Fatal (err )
182+ }
183+ _ , ok = item ["addition" ]
184+ if ! ok {
185+ t .Error ("should be present" )
186+ }
187+ }
188+
155189type isValue_Kind interface {
156190 isValue_Kind ()
157191}
Original file line number Diff line number Diff line change @@ -250,8 +250,12 @@ func (info *structInfo) isZero(rv reflect.Value) bool {
250250 }
251251 for _ , field := range info .fields {
252252 fv := dig (rv , field .index )
253- if ! fv .IsValid () {
254- // TODO: encode NULL?
253+ if ! fv .IsValid () /* field doesn't exist */ {
254+ continue
255+ }
256+ if field .isZero == nil {
257+ // TODO: https://github.com/guregu/dynamo/issues/247
258+ // need to give child structs an isZero
255259 continue
256260 }
257261 if ! field .isZero (fv ) {
You can’t perform that action at this time.
0 commit comments