Skip to content

[dart-dio][dart-dio-next] Support Date Type #9095

@jannikrh

Description

@jannikrh

Is 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions