[dart-dio][dart-dio-next] Support Date Type
See original GitHub issueIs your feature request related to a problem? Please describe.
The OpenAPI definition differentiates between Date and DateTime. The dart-dio-next generator supports only DateTime without the additional timemachine library, which causes deserialization errors for Date on the server side.
Describe the solution you’d like
The goal is to distinguish between Date and DateTime in serialization. Due to BuiltValue only one serializer can be specified for one class. While adding the serializer, FullType
supports optional parameters, which maybe provides a possibility to distinguish between Date and DateTime using {{isDate}}
. The Iso8601DateTimeSerializer
could be extendend by checking these parameters and use DateFormat('yyyy-MM-dd')
to serialize Date.
Describe alternatives you’ve considered
Alternative approaches are to use the dart generator, which already distinguishes between DateTime and Date, or to use the timemachine library. The first approach unfortunately lacks the wide possibilities of Dio like interceptors and the timemachine library adds more dependencies and often requires a conversion between timemachine classes and DateTime.
Additional context
As mentioned in #8869, support for Date would be a useful extension to the next generation dart dio generator @agilob @kuhnroyal. I would like to thank you for the current version of the new generator, it looks very promising.
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (7 by maintainers)
Top GitHub Comments
We could create a custom
Date
class with helpers forto/fromDateTime()
and use that instead.Is it possibile to add the support to Date type also for json_serializable serializer?