-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
got json.UnmarshalTypeError instead of validator.ValidationErrors #3135
Comments
Gin basically uses the |
so gin must use another package to unmarshal because I think it's a huge problem
and the user sends a request with this data
we can only show one of this fields has a problem and the user must send 3 requests and solve its problems one by one to understand all of his fields types are wrong Can you contribute and fix this problem or suggest to me a solution to fix this in my project or suggest me an alternative for |
I'm not a maintainer of Gin, so it's up to you how you want to handle this. In my projects, I have a wrapper around Gin's There are many alternative JSON libraries out there, e.g. https://github.com/goccy/go-json and https://github.com/json-iterator/go. I think Gin even has support for jsoniter: https://github.com/gin-gonic/gin/blob/master/internal/json/jsoniter.go. I haven't tried using alternative JSON libs, though, so I don't know if they provide better error reporting or not. This article lists a few more JSON libs: https://www.pixelstech.net/article/1639285333-Popular-Golang-JSON-libraries-evaluation Worst case scenario, you could try umarshaling twice. First to |
Description
I use ShouldBindJSON for validation and I have a model that has a field with the type float32 name 'salary' when I send string for field salary I expect to get a slice of errors of type go-playground/v10 validator.ValidationErrors or slice of json.UnmarshalTypeError but I get only *json.UnmarshalTypeError
How to reproduce
Expectations
it will be very nice if it return errors as validator.ValidationErrors
or maybe return errors as slice of *json.UnmarshalTypeError so we can generate error messages for all in response
Actual result
it only returns an error for the first field so the user must send request 3 times to solve type problems of his entry
Environment
The text was updated successfully, but these errors were encountered: