Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Converter Factory for Retrofit 2.0
public class RawStringConverter extends Converter.Factory {
@Override
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
//noinspection EqualsBetweenInconvertibleTypes
if (String.class.equals(type)) {
return ResponseBody::string;
}
return null;
}
@Override public Converter<?, RequestBody> toRequestBody(Type type, Annotation[] annotations) {
//noinspection EqualsBetweenInconvertibleTypes
if (String.class.equals(type)) {
try {
return (String value) -> RequestBody.create(MediaType.parse("text/plain"), value);
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.