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
go version go1.21.9 darwin/amd64
2.7.1
Option Yes
package main import ( "context" "encoding/json" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" ) type HelloReq struct { g.Meta `path:"/hello" method:"POST"` Name string `json:"name" v:"required" dc:"Your name"` RawJSON json.RawMessage `json:"rawJson" v:"required|json" dc:"Raw JSON content"` } type HelloRes struct { Name string `json:"name" v:"required" dc:"Your name"` RawJSON json.RawMessage `json:"rawJson" v:"required|json" dc:"Raw JSON content"` } type Hello struct{} func (Hello) Say(ctx context.Context, req *HelloReq) (res *HelloRes, err error) { g.Log().Debugf(ctx, `receive say: %+v`, req) res = &HelloRes{ Name: req.Name, RawJSON: req.RawJSON, } return } func main() { s := g.Server() s.Use(ghttp.MiddlewareHandlerResponse) s.Group("/", func(group *ghttp.RouterGroup) { group.Bind( new(Hello), ) }) s.Run() }
config
server: address: ":8199" openapiPath: "/api.json" swaggerPath: "/swagger"
启动服务测试请求
JSON Object 可以通过验证
curl --location --request POST 'http://127.0.0.1:8199/hello' \ --header 'Content-Type: application/json' \ --data-raw '{ "name": "jack", "rawJson": { "name": "j2" } }'
JSON Array 无法通过验证
curl --location --request POST 'http://127.0.0.1:8199/hello' \ --header 'Content-Type: application/json' \ --data-raw '{ "name": "jack", "rawJson": [ { "name": "j2" } ] }'
See:
gf/util/gvalid/internal/builtin/builtin_json.go
Line 34 in cf37731
JSON Array 验证失效
主要原因
gf/util/gconv/gconv.go
Line 78 in cf37731
The text was updated successfully, but these errors were encountered:
@shuqingzai 建议直接用string接收,使用json.RawMessage会做两次json转换
Sorry, something went wrong.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
@shuqingzai It is recommended to use string to receive directly and use json.RawMessage to do two json conversions
No branches or pull requests
Go version
go version go1.21.9 darwin/amd64
GoFrame version
2.7.1
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
server
config
启动服务测试请求
JSON Object 可以通过验证
JSON Array 无法通过验证
See:
gf/util/gvalid/internal/builtin/builtin_json.go
Line 34 in cf37731
What did you see happen?
JSON Array 验证失效
What did you expect to see?
主要原因
See:
gf/util/gconv/gconv.go
Line 78 in cf37731
The text was updated successfully, but these errors were encountered: