Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4057,3 +4057,40 @@ func TestIssue429(t *testing.T) {
}
}
}

func TestIssue427(t *testing.T) {
type Entity struct {
SomeField1 string
SomeField2 string
SomeField3 string
SomeField4 string
SomeField5 string
SomeField6 string
SomeField7 string
SomeField8 string
SomeField9 string
SomeField10 string
SomeField11 string
SomeField12 string
SomeField13 string
SomeField14 string
SomeField15 string
SomeField16 string
SomeField17 string
}
const src = `{"someField1":"v1","someField17":"v17"}`

var got Entity
if err := json.Unmarshal([]byte(src), &got); err != nil {
t.Fatal(err)
}
assertEq(t, "unmarshal first field", "v1", got.SomeField1)
assertEq(t, "unmarshal last field", "v17", got.SomeField17)

var stream Entity
if err := json.NewDecoder(strings.NewReader(src)).Decode(&stream); err != nil {
t.Fatal(err)
}
assertEq(t, "stream first field", "v1", stream.SomeField1)
assertEq(t, "stream last field", "v17", stream.SomeField17)
}
11 changes: 9 additions & 2 deletions internal/decoder/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,10 @@ func decodeKey(d *structDecoder, buf []byte, cursor int64) (int64, *structFieldS
k := *(*string)(unsafe.Pointer(&key))
field, exists := d.fieldMap[k]
if !exists {
return cursor, nil, nil
field, exists = d.fieldMap[strings.ToLower(k)]
if !exists {
return cursor, nil, nil
}
}
return cursor, field, nil
}
Expand Down Expand Up @@ -657,7 +660,11 @@ func decodeKeyStream(d *structDecoder, s *Stream) (*structFieldSet, string, erro
return nil, "", err
}
k := *(*string)(unsafe.Pointer(&key))
return d.fieldMap[k], k, nil
field, exists := d.fieldMap[k]
if !exists {
field = d.fieldMap[strings.ToLower(k)]
}
return field, k, nil
}

func (d *structDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) error {
Expand Down