We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug
v0.7.0版本之后 BindAndValidate BindForm不能正确解析时间字符串
To Reproduce
Steps to reproduce the behavior:
Expected behavior req.Birthday不应该是空值
Screenshots
Hertz version: v0.7.0 or above
Environment:
Additional context
The text was updated successfully, but these errors were encountered:
现在先用json 来规避吧
Sorry, something went wrong.
我测试了下,如果你的 "MyTime已经重写UnmarshalJSON解析字符串" 是会正常进行参数绑定的;如果你稳定复现的话,可以粘贴一个具体的单测例子。 以下是我的测试 case
type MyTime time.Time func (m *MyTime) UnmarshalJSON(b []byte) error { t := time.Now().AddDate(0, 0, -2) *m = MyTime(t) return nil } type ReqTime struct { Birthday MyTime `json:"birth" form:"birth"` //MyTime已经重写UnmarshalJSON解析字符串 } func TestTime(t *testing.T) { r := protocol.NewRequest("POST", "/foo", nil) now := time.Now().UTC() fmt.Println(now.String()) r.SetRequestURI(fmt.Sprintf("/foo")) r.Header.SetContentTypeBytes([]byte("application/x-www-form-urlencoded")) kv := url.Values{} kv.Set("birth", now.String()) r.SetBody([]byte(kv.Encode())) var req ReqTime err := DefaultBinder().Bind(r, &req, nil) if err != nil { t.Fatalf("unexpected error: %v", err) return } }
No branches or pull requests
Describe the bug
v0.7.0版本之后 BindAndValidate BindForm不能正确解析时间字符串
To Reproduce
Steps to reproduce the behavior:
type MyTime time.Time
type ReqTime struct {
Birthday MyTime json:"birth" form:"birth" //MyTime已经重写UnmarshalJSON解析字符串
}
func Test(ctx context.Context, c *app.RequestContext) {
var req ReqTime
c.BindAndValidate(&req) // v0.9.0 Birthday是空的。换成v0.6.2就正常了
c.BindForm(&req) // v0.9.0 Birthday也是空的
}
Expected behavior
req.Birthday不应该是空值
Screenshots
Hertz version:
v0.7.0 or above
Environment:
Additional context
The text was updated successfully, but these errors were encountered: