-
Notifications
You must be signed in to change notification settings - Fork 8k
-
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
BindQuery to custom type #2631
Comments
I think you can bind it using a binding like: |
Hello, Thanks for your help, however same error with:
|
In the |
Same error with all versions listed. |
Hello,
` func IsValidUUID(u string) bool { ` |
Hello @zadil, Thanks for your answer, however, the problem is not on validation. The issue is on binding, which interface can I implement on custom type "ID" to allow binding. |
Hi @edebernis
let me know if this helps |
Related issue: #2673 |
I'm having the same problem. What we need is a way to support custom unmarshalling for non-struct types. If you look at the a simple solution here might just be to first check to see if the destination type supports the unmarshaller interface. Something like: func setWithProperType(val string, value reflect.Value, field reflect.StructField) error {
if _, ok := value.Interface().(json.Unmarshaler); ok {
return json.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface())
}
switch value.Kind() {
... |
@ssoroka Two remarks:
There are some other things to consider, too. Check out this discussion: #2673 |
that's fine with me, and would solve my problem. At the moment there is no way to do this. |
Here's what I ended up with func setWithProperType(val string, value reflect.Value, field reflect.StructField) error {
if u, ok := value.Addr().Interface().(encoding.TextUnmarshaler); ok {
return u.UnmarshalText(bytesconv.StringToBytes(val))
} |
This is still an issue. When will it be fixed in gin? |
Description
I would like to bind a query parameter into a custom type (uuid.UUID).
Is there an interface to implement on custom type to support this ?
It works with json binding for example, as custom type implements Unmarshaler interface.
How to reproduce
Expectations
Actual result
Environment
The text was updated successfully, but these errors were encountered: