mirror of
https://github.com/gin-gonic/gin.git
synced 2026-11-22 02:43:36 +08:00
The time_format, time_utc, and time_location struct tags work correctly for form/query binding (ShouldBindQuery, ShouldBindForm) but are completely ignored when using ShouldBindJSON or ShouldBindBodyWithJSON. encoding/json only understands RFC3339 for time.Time fields, so custom time formats such as "2006-01-02 15:04:05" or "unix" produce a parse error like: parsing time "2001-11-11 11:11:11" as "2006-01-02T15:04:05Z07:00": cannot parse " 11:11:11" as "T" This fix replaces the single-pass JSON decode with a field-by-field decode when the target struct has any time.Time field that carries a time_format tag. Fields with time_format are parsed by the existing setTimeField helper (same one used by form binding), so all existing tag features (time_format, time_utc, time_location, unix/unixmilli/ unixmicro/unixnano) work identically in JSON binding. Fast path: when the struct has no time_format tags at all, the original single-pass decoder.Decode path is used (zero overhead). Fixes #2170