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

Factory converter with global converter #173

Open
Study-Log opened this issue Sep 18, 2020 · 2 comments
Open

Factory converter with global converter #173

Study-Log opened this issue Sep 18, 2020 · 2 comments
Labels
investigation The issue needs further investigation

Comments

@Study-Log
Copy link
Contributor

The current chopper provides two ways to convert Request and Response.
The first version is to define the global default converter through the ChopperClient constructor. The second version is FactoryConverter annotation.
When we use both of them, the global default converter is ignored and the FactoryConverter is only being used.
Is there any plan to relay both of them?
For example,

void Sumfunction() {
  final chopper = ChopperClient(
    baseUrl: 'https://jsonplaceholder.typicode.com',
    services: [
      TodosListService.create(),
    ],
    converter: JsonConverter(),
  );
}

class SomeChopperService {
  // ...
  @Get(path: '/{id}')
  @FactoryConverter(response: convertResponse)
  Future<Response<Todo>> getTodo(@Path() int id);
}

Response<Todo> convertResponse<T, InnerType>(Response response) {
  final body = response.body;  // => body will be jsonMap by the relay of the `JsonConverter`
  return response.copyWith(body: Todo.fromJson(body));
}

If this is possible, converter can be Iterable like intercepter.

@stewemetal
Copy link
Collaborator

stewemetal commented Jan 15, 2021

Converter methods defined with @FactoryConverter will - by design - override the default converter. @FactoryConverter's intended usage is overriding the default converter behavior selectively for individual requests.

However, if null is passed to any of @FactoryConverter's parameters then Chopper should use the default converter for that conversion. This needs investigation.

@stewemetal stewemetal added the investigation The issue needs further investigation label Jan 15, 2021
@lejard-h
Copy link
Owner

We could add a boolean to FactoryConverter to specify if we want to use global converter first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigation The issue needs further investigation
Projects
None yet
Development

No branches or pull requests

3 participants