Pārlūkot izejas kodu

fix #250 case insensitive field match

Tao Wen 7 gadi atpakaļ
vecāks
revīzija
06e0f9391e
2 mainītis faili ar 20 papildinājumiem un 0 dzēšanām
  1. 5 0
      reflect_struct_decoder.go
  2. 15 0
      value_tests/struct_test.go

+ 5 - 0
reflect_struct_decoder.go

@@ -31,6 +31,11 @@ func decoderOfStruct(ctx *ctx, typ reflect2.Type) ValDecoder {
 	for k, binding := range bindings {
 	for k, binding := range bindings {
 		fields[k] = binding.Decoder.(*structFieldDecoder)
 		fields[k] = binding.Decoder.(*structFieldDecoder)
 	}
 	}
+	for k, binding := range bindings {
+		if _, found := fields[strings.ToLower(k)]; !found {
+			fields[strings.ToLower(k)] = binding.Decoder.(*structFieldDecoder)
+		}
+	}
 	return createStructDecoder(ctx, typ, fields)
 	return createStructDecoder(ctx, typ, fields)
 }
 }
 
 

+ 15 - 0
value_tests/struct_test.go

@@ -63,6 +63,21 @@ func init() {
 			d *time.Timer
 			d *time.Timer
 		})(nil),
 		})(nil),
 		input: `{"a": 444, "b":"bad", "C":256, "d":{"not":"a timer"}}`,
 		input: `{"a": 444, "b":"bad", "C":256, "d":{"not":"a timer"}}`,
+	}, unmarshalCase{
+		ptr: (*struct {
+			A string
+			B string
+			C string
+			D string
+			E string
+			F string
+			G string
+			H string
+			I string
+			J string
+			K string
+		})(nil),
+		input: `{"a":"1","b":"2","c":"3","d":"4","e":"5","f":"6","g":"7","h":"8","i":"9","j":"10","k":"11"}`,
 	})
 	})
 	marshalCases = append(marshalCases,
 	marshalCases = append(marshalCases,
 		struct {
 		struct {