-
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
Cannot Parse time with time_format set from JSON #1193
Comments
Figured out the answer. Has nothing to do with gin but what the golang JSON Decoder expects for time values. It must be in the format of RFC3339 in order to be successfully decoded when using the JSON binder for However, it should be addressed that this creates an inconsistency when binding from form data vs binding from JSON data. When binding form data, if you set the If not fixed in gin, this should at least be addressed in the docs. I'd be happy to make a PR! |
I still have this issue (bug) |
@NarHakobyan How did you solve this problem? |
The gin use the default golang json unmarshaler, where you can use a custom type to unmarshal a value as you want.
|
|
Using the custom type to unmarshal a value that casing the sql can't convert the type. what should I do? @vkd |
@zsirfs Could you please expand your question with more details? What does the request look like? What is your expectation? |
If you need sql to be able to handle your custom type you must implement Scanner and Valuer interfaces for the type as shown in this example |
can i "unmarshal" case in point
and I've custom marshalar
it works if tag is |
@ahhmarr this should work for you:
|
thnx for the reply @vkd Actually, I'm trying to send multipart data (an image in the payload as well)
have the struct as
i get error when i try to bind validation smth like
|
Ok, I see. Could you try this:
The point is the form binding is not calling |
refer to this: https://segmentfault.com/a/1190000022264001 |
nice, a elegant solution~~ |
@vkd iso time can pass the json decode, I have made a test to it |
Problem:
I can't parse a time string even when setting the time_format value. Here is my struct,
and the request I am making of which I immediately call
c.ShouldBindJSON(&class)
,Regardless of sending the correct format, I always get this error back,
"parsing time \"\"2017-01-08\"\" as \"\"2006-01-02T15:04:05Z07:00\"\": cannot parse \"\"\" as \"T\""
Any help is appreciated. Thanks!
The text was updated successfully, but these errors were encountered: