-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Can't bind list of struct pointer in query #3659
Comments
Hey @claneo, I was able to successfully reproduce this issue from your example code snippet above and was able to get the Root Cause:As you suggested, the Solution:In your example, change I've updated your example as below for reference with comment: package main
import (
"github.com/gin-gonic/gin"
)
type Struct struct {
Id int64 `json:"id"`
}
type Req struct {
Items []Struct `json:"items" form:"items"` // Use []Struct instead of []*Struct here
}
func main() {
r := gin.Default()
r.GET("/api", func(c *gin.Context) {
req := new(Req)
err := c.Bind(req)
if err != nil {
c.JSON(500, err.Error())
return
}
c.JSON(200, req)
})
_ = r.Run("127.0.0.1:8080")
} I've tested the above code with Gin v1.9.1 and it works well. Hope it works for you too. |
Hi, @omkar-foss , Thanks for your reply. I know this problem can been fixed by change So I think maybe gin can support this feature, to cover more use case. |
Hey @claneo, indeed, it might be a good idea to keep support for If we plan on re-adding support for @vkd @thinkerou It would be great if you could help by giving us some background about why the |
Thanks @omkar-foss for bringing this up. As far as I remember, there wasn't a test case for such a scenario, and that case block was removed as a redundant. |
…n-gonic#3659) This support was previously available in Gin, but was removed in commit 0d50ce8 since there wasn't a test case for such a scenario, and so the case block was removed as a redundant one.
This support was previously available in Gin, but was removed in commit 0d50ce8 since there wasn't a test case for such a scenario, and so the case block was removed as a redundant one.
Hey @vkd, thanks a lot for your reply. I've raised this PR which consists of the re-addition of pointer support (with tests), the code change is an adaptation of the change in this commit where the support was removed as well as suggested by @claneo above. |
The pointer support in url query params (using []*Struct for binding query params) was previously available in Gin, but was removed in commit 0d50ce8 since there wasn't a test case for such a scenario, and so the case block was removed as a redundant one.
The pointer support in url query params (using []*Struct for binding query params) was previously available in Gin, but was removed in commit 0d50ce8 since there wasn't a test case for such a scenario, and so the case block was removed as a redundant one.
Description
Can't bind list of struct pointer in query
It seem like the pointer support was lost in this commit
0d50ce8?diff=split#diff-b0f2c06474cd98fa718e657b7037a516ada93c3de8f51fd795bfdf0ab3e2ade5L133-L138
I try to add these lines into
setWithProperType
,then the problem is resolvedHow to reproduce
Expectations
Actual result
Environment
The text was updated successfully, but these errors were encountered: