Skip to content

Instantly share code, notes, and snippets.

@oldergod
Last active December 6, 2016 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oldergod/1c20fde0787afe8840cc108a6abf902b to your computer and use it in GitHub Desktop.
Save oldergod/1c20fde0787afe8840cc108a6abf902b to your computer and use it in GitHub Desktop.
Retrofit and envelopes
public class LoginContextUnwrappingConverter extends Converter.Factory {
@Override
public Converter<ResponseBody, LoginContext>
responseBodyConverter(Type type,
Annotation[] annotations,
Retrofit retrofit) {
if (type != LoginContext.class) {
return null;
}
final Converter<ResponseBody, LoginResponse> delegate =
retrofit.nextResponseBodyConverter(this,
LoginResponse.class,
annotations);
return body -> {
LoginResponse wrapper = delegate.convert(body);
return wrapper.context();
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment