panic when access map data which key is user defined type
Closed this issue · 5 comments
echoface commented
type String string
type X struct {
Code String `json:"code,omitempty"`
}
x := map[String]*X{
"abc": {
Code: "123",
},
}
var err error
var expr jp.Expr
if expr, err = jp.ParseString("$.abc.code"); err != nil {
panic(err)
}
var values []interface{}
values = expr.Get(x) // panic here
fmt.Println("values:", values)
output:
2 panic: reflect.Value.MapIndex: value of type string is not assignable to type main.String
3
4 goroutine 1 [running]:
5 reflect.Value.assignTo({0x4efca0?, 0xc0000140b0?, 0x5e9de0?}, {0x50dcd7, 0x16}, 0x4efba0, 0x0)
6 /home/linuxbrew/.linuxbrew/Cellar/go@1.22/1.22.6/libexec/src/reflect/value.go:3356 +0x299
7 reflect.Value.MapIndex({0x4f4600?, 0xc0000b8210?, 0x7fd2ede54108?}, {0x4efca0, 0xc0000140b0, 0x98})
8 /home/linuxbrew/.linuxbrew/Cellar/go@1.22/1.22.6/libexec/src/reflect/value.go:1821 +0xe8
9 github.com/ohler55/ojg/jp.Expr.reflectGetChild({0x0?, 0x4f4600?, 0x0?}, {0x4f4600?, 0xc0000b8210?}, {0xc0000120d8, 0x3})
10 /home/gonghuan/go/pkg/mod/github.com/ohler55/ojg@v1.24.0/jp/get.go:1657 +0x285
11 github.com/ohler55/ojg/jp.Expr.Get({0xc0000ba040, 0x3, 0x4}, {0x4f4600, 0xc0000b8210})
12 /home/gonghuan/go/pkg/mod/github.com/ohler55/ojg@v1.24.0/jp/get.go:73 +0x5ea8
13 main.main()
14 /home/gonghuan/bytedance/playground/main.go:25 +0xb6
15 exit status 2
ohler55 commented
I'll look into it.
ohler55 commented
Took longer than expected to get to this. My apologies. Please try the "non-string-map-keys" branch.
echoface commented
thanks ,i will have a try
Peter Ohler ***@***.***> 于 2024年9月15日周日 05:57写道:
… Took longer than expected to get to this. My apologies. Please try the
"non-string-map-keys" branch.
—
Reply to this email directly, view it on GitHub
<#185 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACNO77MYTZDPUV3K23YD3OLZWSWL3AVCNFSM6AAAAABNT2YX3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJRGE3TEMBYGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
echoface commented
thanks, again; seems fixed;
so, it will merge into main in next release tag ?
ohler55 commented
Released. Thanks for finding the issue.