1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-23 11:37:32 +02:00

fix(reflect): don't process ignored struct fields

This commit is contained in:
Javier Provecho Fernandez 2017-07-08 15:32:48 +02:00
parent b1afefe058
commit aaf6160146

View File

@ -200,7 +200,12 @@ func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, err
bindings := []*Binding{} bindings := []*Binding{}
for i := 0; i < typ.NumField(); i++ { for i := 0; i < typ.NumField(); i++ {
field := typ.Field(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 { if field.Type.Kind() == reflect.Struct {
structDescriptor, err := describeStruct(cfg, field.Type) structDescriptor, err := describeStruct(cfg, field.Type)
if err != nil { if err != nil {
@ -231,8 +236,7 @@ func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, err
continue continue
} }
} }
tagParts := strings.Split(field.Tag.Get("json"), ",") fieldNames := calcFieldNames(field.Name, tagParts[0], tag)
fieldNames := calcFieldNames(field.Name, tagParts[0], string(field.Tag.Get("json")))
fieldCacheKey := fmt.Sprintf("%s/%s", typ.String(), field.Name) fieldCacheKey := fmt.Sprintf("%s/%s", typ.String(), field.Name)
decoder := fieldDecoders[fieldCacheKey] decoder := fieldDecoders[fieldCacheKey]
if decoder == nil { if decoder == nil {