diff --git a/dsl/matcher.go b/dsl/matcher.go index f084bf823..9e42431a6 100644 --- a/dsl/matcher.go +++ b/dsl/matcher.go @@ -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 diff --git a/dsl/matcher_test.go b/dsl/matcher_test.go index 599851fb4..4800ff17d 100644 --- a/dsl/matcher_test.go +++ b/dsl/matcher_test.go @@ -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{} @@ -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{