Created
October 28, 2015 11:48
-
-
Save antonshkurenko/48cf924a68a86199bf44 to your computer and use it in GitHub Desktop.
Converter Factory for Retrofit 2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/square/retrofit/blob/07d1f3de5e0eb11fb537464bd14fdbacfc9e55a7/retrofit/src/test/java/retrofit/ToStringConverterFactory.java