Closed
Description
The current implementation seems that it does not care of field name cases(case insensitive) in design.
But since some public API require case sensitive decoder, this library needs to do so against them.
c.f. https://github.com/binance-exchange/binance-official-api-docs/blob/master/user-data-stream.md
test:
import (
"encoding/json"
"github.com/json-iterator/go"
)
type X struct {
Upper bool `json:"M"`
Lower bool `json:"m"`
}
func TestJSON(t *testing.T) {
inOrder := []byte(`{"M":false,"m":true}`)
swapped := []byte(`{"m":true,"M":false}`)
var x X
err := json.Unmarshal(inOrder, &x)
if err != nil {
panic(err)
}
test(t, "encoding/json, in order", x)
err = json.Unmarshal(swapped, &x)
if err != nil {
panic(err)
}
test(t, "encoding/json, swapped", x)
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(inOrder, &x)
if err != nil {
panic(err)
}
test(t, "jsoniter, in order", x)
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(swapped, &x)
if err != nil {
panic(err)
}
test(t, "jsoniter, swapped", x)
}
func test(t *testing.T, label string, x X) {
if x.Upper {
t.Errorf("%s: x.Upper is not false", label)
return
}
if !x.Lower {
t.Errorf("%s: x.Lower is not true", label)
return
}
}
result:
--- FAIL: TestJSON (0.00s)
json_test.go: jsoniter, swapped: x.Lower is not true
FAIL
Metadata
Metadata
Assignees
Labels
No labels