leancloud / go-sdk

Golang SDK for LeanCloud Storage and LeanEngine
https://leancloudblog.com/announce-leancloud-go-sdk/
Apache License 2.0
12 stars 6 forks source link

encodeStruct 应该读取json tag #51

Open KevinGong2013 opened 2 years ago

KevinGong2013 commented 2 years ago

https://github.com/leancloud/go-sdk/blob/7d89f2fbc445c585336655a3fd59a3d4704639cc/leancloud/encoding.go#L265-L282

例如自定一个class 如下:

type Foo struct {
    leancloud.Object
    Rule               struct {
        Month     int `json:"month"`
        Day       int `json:"day"`
    } `json:"rule"`
}

这个Foo对象save以后 rule列应该是 {"month": 1, "day": 1} 而不是{"Month": 1, "Day": 1}

bigzhu commented 2 years ago

我也遇到一样的问题, 某字段是一个 Array, Array 里放了一堆 struct 对象.

存入库中后发现, 这些 struct 对象都没有读取其 json tag, 而是用了大写开头的字段名.

bigzhu commented 2 years ago

提了一个 pull request https://github.com/leancloud/go-sdk/pull/52