Prechádzať zdrojové kódy

fix tag field name not used bug

Tao Wen 9 rokov pred
rodič
commit
e7ec3988a6
1 zmenil súbory, kde vykonal 4 pridanie a 0 odobranie
  1. 4 0
      jsoniter_reflect.go

+ 4 - 0
jsoniter_reflect.go

@@ -713,12 +713,16 @@ func decoderOfStruct(type_ reflect.Type) (Decoder, error) {
 		}
 		decoder := fieldDecoders[fieldDecoderKey]
 		tagParts := strings.Split(field.Tag.Get("json"), ",")
+		// if fieldNames set by extension, use theirs, otherwise try tags
 		if fieldNames == nil {
+			/// tagParts[0] always present, even if no tags
 			switch tagParts[0] {
 			case "":
 				fieldNames = []string{field.Name}
 			case "-":
 				fieldNames = []string{}
+			default:
+				fieldNames = []string{tagParts[0]}
 			}
 		}
 		if decoder == nil {