-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
UnmarshalParam doesn't seem to be called on POST #1405
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
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I'm also running into this issue. Are there plans to fix it? UnmarshalParam(string) isn't being called as far as I can tell. |
Is there any fix? Can't call for post json data. |
This is working as intended. So for this example to work with // UnmarshalJSON converts JSON to object
func (t *Timestamp) UnmarshalJSON(b []byte) error {
ts, err := time.Parse(time.RFC3339, strings.Trim(string(b), `"`))
*t = Timestamp(ts)
return err
}
|
Thank you for your Help sir. I have another question not relavent to topic but, how to bind nested form-data with multipart with echo? JSON bind works perfectly. im stuck with form-data (using inertia-js if a request have a file turning form type to multipart, form-data) sample data is: type ProductUpdateRequest struct {
ID uint `json:"id" form:"id" query:"id" validate:"required"`
Name string `json:"name" form:"name" query:"name" validate:"required"`
Description string `json:"description" form:"description" query:"description" validate:"required"`
DID uint `json:"did" form:"did" query:"did" validate:"required"`
ProductMainID string `json:"product_main_id" form:"product_main_id" query:"product_main_id" validate:"required"`
...
Items []struct{
Images []*multipart.FileHeader `json:"images" form:"images" query:"images"`
ID uint `json:"id" form:"id" query:"id" validate:""`
Barcode string `json:"barcode" form:"barcode" query:"barcode" validate:"required"`
...
} `json:"stockItems" form:"stockItems" query:"stockItems" validate:"required,gt=0,dive,required"`
}
|
Binding from Looking at https://inertiajs.com/forms and https://inertiajs.com/forms#classic-xhr-submits you could transform your form before sending. These are hacky but you could: ala var payload struct{
ID int64
}
if err := json.Unmarshal([]byte(c.FormValue("form_fields_as_json_string")), &payload); err != nil { b) if those images are not huge you could transform form to json and images to base64 encoded fields in json. |
Thank you for your kindness and help sir. I am working on it. |
Uh oh!
There was an error while loading. Please reload this page.
Issue Description
When posting a struct that includes a field that implements Echo#BindUnmarshaler, it doesn't seem to call UnmarshalParam for it when calling c.Bind. It does however work on GET with query parameters (there is a test for this already).
Checklist
Expected behaviour
I'd expect Echo to call UnmarshalParam when Binding to a struct. The documentation at https://echo.labstack.com/guide/request gives an example for a Timestamp but it doesn't include the struct that was being used. It might be nice to include that in a future version.
Actual behaviour
Given the test below (added to bind_test.go) I get the following error:
Steps to reproduce
Add the test below to bind_test.go and run the test.
Working code to debug
Version/commit
Tested with Echo commit 81a6608.
The text was updated successfully, but these errors were encountered: