Pārlūkot izejas kodu

fix tag field name not used bug

Tao Wen 9 gadi atpakaļ
vecāks
revīzija
e7ec3988a6
1 mainītis faili ar 4 papildinājumiem un 0 dzēšanām
  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 {