Skip to content

Commit

Permalink
Match should skip unexported fields as they won't be serialized (#201)
Browse files Browse the repository at this point in the history
fix: match should skip unexported fields as they won't be serialized
  • Loading branch information
codyaray authored Feb 9, 2022
1 parent 2f6d45e commit 25a5ad5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dsl/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ func match(srcType reflect.Type, params params) Matcher {

for i := 0; i < srcType.NumField(); i++ {
field := srcType.Field(i)
// Skip unexported fields.
if field.PkgPath != "" {
continue
}
fieldName := getJsonFieldName(field)
if fieldName == "" {
continue
Expand Down
10 changes: 10 additions & 0 deletions dsl/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ func TestMatch(t *testing.T) {
Word string `json:"word"`
WordDash string `json:"-,"`
}
type unexportedDTO struct {
unexported string
}
str := "str"
type args struct {
src interface{}
Expand Down Expand Up @@ -752,6 +755,13 @@ func TestMatch(t *testing.T) {
"-": Like("string"),
},
},
{
name: "recursive case - struct with unexported field",
args: args{
src: unexportedDTO{},
},
want: StructMatcher{},
},
{
name: "base case - string",
args: args{
Expand Down

0 comments on commit 25a5ad5

Please sign in to comment.