Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryParam - optional converter option #673

Open
moshe5745 opened this issue May 9, 2024 · 0 comments
Open

QueryParam - optional converter option #673

moshe5745 opened this issue May 9, 2024 · 0 comments

Comments

@moshe5745
Copy link
Contributor

moshe5745 commented May 9, 2024

Is your feature request related to a problem? Please describe.
Right now to make a consistent way to convert DateTime to String we need to use our code.
For instance, we need to use a helper function that converts a DateTime to a String in a specific format when we calling retrofit-generated code.

  @GET('/some-thing')
  Future<dynamic> getData(
    @Query('fromDate') String fromDate,
  );

apiClient.getData(helperConverter(DateTime.now())) 

This is not an optimal solution. Because the helper function code is not directly connected to Retrofit.
So if you working in big team someone maybe wouldn’t know about the helper function or would forgot to use it.

Describe the solution you'd like
To add an option of converter function to "Query" annotation.

  @GET('/some-thing')
  Future<dynamic> getData(
    @Query('fromDate', helperConverter) String fromDate,
  );

apiClient.getData(DateTime.now()) 

Describe alternatives you've considered
Maybe to use new annotation like json_serializable uses.

class EpochDateTimeConverter implements JsonConverter<DateTime, int> {
  const EpochDateTimeConverter();

  @override
  DateTime fromJson(int json) => DateTime.fromMillisecondsSinceEpoch(json);

  @override
  int toJson(DateTime object) => object.millisecondsSinceEpoch;
}

  @GET('/some-thing')
  Future<dynamic> getData(
    @Query('fromDate', helperConverter) @EpochDateTimeConverter() String fromDate,
  );

@moshe5745 moshe5745 changed the title QueryParam parameter optional converter option QueryParam - optional converter option May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant