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

ResponseHandler should allow to pass our own converter #39

Closed
javaboboApp opened this issue Jun 25, 2021 · 5 comments
Closed

ResponseHandler should allow to pass our own converter #39

javaboboApp opened this issue Jun 25, 2021 · 5 comments

Comments

@javaboboApp
Copy link

ResponseHandler should allow to pass our own converter NullOnEmptyConverterFactory extends Converter.Factory.
I am not able to deal with reponses 204 using GET method and empty body because of this.

@haroldadmin
Copy link
Owner

If your response has an empty body, use the Unit as the success response type. See here

@javaboboApp
Copy link
Author

That is true but what happens when api returns sometimes 204 and other times an json object. We get an error...

@javaboboApp
Copy link
Author

It would be better if you add another response such us Success (header..) without body and other with body, so developer have control about this kind of situations.

@haroldadmin
Copy link
Owner

I'm not sure what's the best way to handle your usecase. If your API response is unpredictable, it might be best to not use the NetworkResponse class as its return type. You could instead return an Any from your API interface, and perform checks at runtime to identify the type of response.

Response converter factories usually don't accept other response converters as input parameters. If you have multiple types of response converters, you should add them to Retrofit directly.

Retrofit.Builder()
    .addCallAdapterFactory(...)
    .addCallAdapterFactory(...)
    .addCallAdapterFactory(...)
    .addCallAdapterFactory(NetworkResponseAdapterFactory())
    .build()

@javaboboApp
Copy link
Author

umm I see yeah is another way to solve this issue but what I have done in this case is add a new type of success response called: SuccessWithEmptyBody so I just have modified library to support this kind of situation.

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

2 participants