guregu / null

reasonable handling of nullable values
BSD 2-Clause "Simplified" License
1.84k stars 238 forks source link

Request parsing for null.Time #51

Closed milosmns closed 4 years ago

milosmns commented 4 years ago

I tried this with Gin-Gonic

type AddUserRequest struct {
  // some other properties
  DateOfBirth               null.Time   `json:"user_birthday" time_format:"2006-01-02"`
}

When I send

{
  // some other stuff
  "user_birthday": "2000-04-05"
}

I still get the (infamous?) parsing time \"\"2000-04-05\"\" as \"\"2006-01-02T15:04:05Z07:00\"\": cannot parse \"\"\" as \"T\"" error.

Is there a workaround for this issue? I don't want to send a string and parse manually.

Thanks!

guregu commented 4 years ago

Sorry but this library uses this standard library's time.Time JSON marshaler which requires that it be in RFC 3339 format. If you'd like to add support for other formats feel free to fork.