-
Notifications
You must be signed in to change notification settings - Fork 1k
it needs to distinguish upper/lower field names in a case #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
the stdlib does not care the case, so we need to be compatible. |
The stdlib cares, at least Go 1.9 does while both of upper and lower cased fields exist in a struct. |
The following test shows how the stdlib handles: import (
"encoding/json"
"fmt"
)
type UpperOnly struct {
Upper bool `json:"M"` // type: bool
}
type LowerOnly struct {
Lower int `json:"m"`. // type: int
}
type Both struct {
Upper bool `json:"M"`
Lower int `json:"m"`
}
func TestJSON(t *testing.T) {
data := []byte(`{"m":3,"M":true}`)
swap := []byte(`{"M":true,"m":3}`)
var upperOnly UpperOnly
if err := json.Unmarshal(data, &upperOnly); err != nil {
t.Error("upperOnly, data:", err)
}
if err := json.Unmarshal(swap, &upperOnly); err != nil {
t.Error("upperOnly, swap:", err)
}
var lowerOnly LowerOnly
if err := json.Unmarshal(data, &lowerOnly); err != nil {
t.Error("lowerOnly, data:", err)
}
if err := json.Unmarshal(swap, &lowerOnly); err != nil {
t.Error("lowerOnly, swap:", err)
}
var both Both
if err := json.Unmarshal(data, &both); err != nil {
t.Error("both, data:", err)
}
if err := json.Unmarshal(swap, &both); err != nil {
t.Error("both, swap:", err)
}
fmt.Printf("%#v\n", both)
} result:
|
Now it works. |
zhenzou
pushed a commit
to zhenzou/jsoniter
that referenced
this issue
Feb 2, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
result:
The text was updated successfully, but these errors were encountered: