mirror of
https://github.com/json-iterator/go.git
synced 2025-05-28 22:17:38 +02:00
fix #250 case insensitive field match
This commit is contained in:
parent
ca39e5af3e
commit
06e0f9391e
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user