Skip to content

Instantly share code, notes, and snippets.

@balrampandey19
Created October 24, 2016 09:43
Show Gist options
  • Save balrampandey19/da57598d2078b27bf802285d469a76c9 to your computer and use it in GitHub Desktop.
Save balrampandey19/da57598d2078b27bf802285d469a76c9 to your computer and use it in GitHub Desktop.
Retrofit 2.0 to String converter
If you are using Protocol buffer or Flat buffer and want to get Byte String response for server-:
```
public class ToStringConverterFactory extends Converter.Factory {
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
if (String.class.equals(type)) {
return new Converter<ResponseBody, String>() {
@Override
public String convert(ResponseBody value) throws IOException {
return value.string();
}
};
}
return null;
}
}
```
@balrampandey19
Copy link
Author

Retrofit 2.0 to String converter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment