Skip to content

Commit

Permalink
Merge pull request #41 from fogfish/fix-encode
Browse files Browse the repository at this point in the history
fix encode of empty objects
  • Loading branch information
fogfish authored Sep 25, 2021
2 parents d9195bd + da8f3d0 commit 4832827
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions id.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func Encode(av *dynamodb.AttributeValue, id curie.IRI, val interface{}) error {
return err
}

if gen.M == nil {
gen.M = make(map[string]*dynamodb.AttributeValue)
}
gen.M["id"] = uid

*av = *gen
Expand Down
14 changes: 14 additions & 0 deletions id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,17 @@ func TestEncodeDecode(t *testing.T) {
IfTrue(curie.Eq(core.ID, some.ID)).
IfTrue(*core.Link == *some.Link)
}

func TestEncodeDecodeKeyOnly(t *testing.T) {
core := MyType{ID: curie.New("test:a/b")}

av, err := dynamodbattribute.Marshal(core)
it.Ok(t).IfNil(err)

var some MyType
err = dynamodbattribute.Unmarshal(av, &some)
it.Ok(t).IfNil(err)

it.Ok(t).
IfTrue(curie.Eq(core.ID, some.ID))
}

0 comments on commit 4832827

Please sign in to comment.