gogf / gf

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
https://goframe.org
MIT License
11.59k stars 1.58k forks source link

util/gconv: wrong conversion #3868

Open qinyuguang opened 3 hours ago

qinyuguang commented 3 hours ago

Go version

1.22

GoFrame version

2.7.3/2.7.4

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

package main

import (
    "log"

    "github.com/gogf/gf/v2/encoding/gjson"
    "github.com/gogf/gf/v2/util/gconv"
)

type Config struct {
    Enable   bool
    Spec     string
    PoolSize int
}

func main() {

    data := gjson.New(`[{"enable":false,"spec":"a"},{"enable":true,"poolSize":1}]`)

    var configs []*Config
    if err := gconv.Structs(data, &configs); err != nil {
        log.Print(err)
        return
    }

    if configs[1].PoolSize == 0 {
        log.Print("fail")
        return
    }

    log.Print("success")
}

What did you see happen?

Run multiple times, there is a probability that the output fail

What did you expect to see?

all success

qinyuguang commented 3 hours ago

If give the struct json tags, there is no problem...

@gqcn