Gin's request validation feature is not working when the request body (JSON) represents an array of objects
Ex:
[
{
"field1":"aaa",
"field2":"bbb"
}
]
code:
type item struct {
Field1 string `json:"field1" binding:"required"`
Field2 string `json:"field2" binding:"required"`
}
var items []item
err := c.BindJSON(&items)
To be more clear, the validation logic in gin is expecting the root object to be a struct and hence bails out when an array type gets passed.
what is best way to validate each object in an array passed in the body?