You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please provide source code and commit sha if you found a bug.
Review existing issues and provide feedback or react to them.
Description
when I declare a struct type Test struct { Start time.Time form:"start"}
I can send a request /test?start=2023-09-02T15:00:00Z. But, When I define a custom time type, like this:
`
type Time struct {
time.Time
}
type Test struct {
Start Time form:"start"
}
`
When I send a request, I get error "invalid character '-' after top-level value".
How to reproduce
package main
import (
"fmt"
"net/http"
"time"
"github.com/gin-gonic/gin"
)
type Time struct {
time.Time
}
type Test struct {
Start Time `form:"start"`
}
func main() {
engine := gin.Default()
engine.GET("/test", func(c *gin.Context) {
var test Test
/*******/
query := c.Request.URL.Query()
fmt.Println(query)
if err := c.ShouldBindQuery(&test); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
fmt.Println(test)
})
engine.Run(":8080")
}
Thanks, but I don't want to add "" in request. because time.Time can do it without "". In source code, I found error in setWithProperType case reflect.Struct, when value is time.Time, the function will call setTimeField, but other type will call json.Unmarshal. I am finding a way to solve it, maybe there a way that entering case rteflect.Ptr can solve it(I guess)
Description
when I declare a struct
type Test struct { Start time.Time
form:"start"}
I can send a request /test?start=2023-09-02T15:00:00Z. But, When I define a custom time type, like this:
`
type Time struct {
time.Time
}
type Test struct {
Start Time
form:"start"
}
`
When I send a request, I get error "invalid character '-' after top-level value".
How to reproduce
Expectations
Actual result
Environment
The text was updated successfully, but these errors were encountered: