goccy / go-json

Fast JSON encoder/decoder compatible with encoding/json for Go
MIT License
3.12k stars 148 forks source link

case-insensitive key matching not working with nested structs #470

Open liberize opened 1 year ago

liberize commented 1 year ago

example:

package main

import (
    "fmt"
    "github.com/goccy/go-json"
)

type Base struct {
    B string `json:"bb"`
}

type Test struct {
    Base
    A string `json:"aA"`
}

func main() {
    b := &Test{}
    err := json.Unmarshal([]byte(`{"Aa":"111","Bb":"222"}`), b)
    fmt.Printf("b: %v, err: %v\n", b, err)
}

prints:

b: &{{} }, err: <nil>

change json:"bB" to json:"bb" then it works:

b: &{{222} 111}, err: <nil>

tested with go 1.14.5 and go-json master

xin-tsla commented 1 year ago

I think it was because you may need to change the example input data as well.