From aaf6160146c8a740f8c1e426d173518df89ba70f Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Sat, 8 Jul 2017 15:32:48 +0200 Subject: [PATCH] fix(reflect): don't process ignored struct fields --- feature_reflect_extension.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/feature_reflect_extension.go b/feature_reflect_extension.go index b8c9980..f553e43 100644 --- a/feature_reflect_extension.go +++ b/feature_reflect_extension.go @@ -200,7 +200,12 @@ func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, err bindings := []*Binding{} for i := 0; i < typ.NumField(); i++ { field := typ.Field(i) - if field.Anonymous && (field.Tag.Get("json") == "" || strings.Split(field.Tag.Get("json"), ",")[0] == "") { + tag := field.Tag.Get("json") + tagParts := strings.Split(tag, ",") + if tag == "-" { + continue + } + if field.Anonymous && (tag == "" || tagParts[0] == "") { if field.Type.Kind() == reflect.Struct { structDescriptor, err := describeStruct(cfg, field.Type) if err != nil { @@ -231,8 +236,7 @@ func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, err continue } } - tagParts := strings.Split(field.Tag.Get("json"), ",") - fieldNames := calcFieldNames(field.Name, tagParts[0], string(field.Tag.Get("json"))) + fieldNames := calcFieldNames(field.Name, tagParts[0], tag) fieldCacheKey := fmt.Sprintf("%s/%s", typ.String(), field.Name) decoder := fieldDecoders[fieldCacheKey] if decoder == nil {