From cdf2498285262b37cc383439bc291f5bf2ee0e27 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sat, 22 Aug 2020 18:15:39 +0900 Subject: [PATCH] Fix processing of anonymous field --- encode_compile.go | 1 - struct_field.go | 12 +++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/encode_compile.go b/encode_compile.go index 8d81da9..9cab925 100644 --- a/encode_compile.go +++ b/encode_compile.go @@ -622,7 +622,6 @@ type structFieldPair struct { } func (e *Encoder) anonymousStructFieldPairMap(typ *rtype, tags structTags, valueCode *structFieldCode) map[string][]structFieldPair { - //fmt.Println("type = ", typ, "valueCode = ", valueCode.dump()) anonymousFields := map[string][]structFieldPair{} f := valueCode var prevAnonymousField *structFieldCode diff --git a/struct_field.go b/struct_field.go index b2a6f50..bb822b3 100644 --- a/struct_field.go +++ b/struct_field.go @@ -10,9 +10,15 @@ func getTag(field reflect.StructField) string { } func isIgnoredStructField(field reflect.StructField) bool { - if field.PkgPath != "" && !field.Anonymous { - // private field - return true + if field.PkgPath != "" { + if field.Anonymous { + if !(field.Type.Kind() == reflect.Ptr && field.Type.Elem().Kind() == reflect.Struct) && field.Type.Kind() != reflect.Struct { + return true + } + } else { + // private field + return true + } } tag := getTag(field) if tag == "-" {