首先,感谢一叶飘舟。给我灵感。
以及他分享的博文,从源码的角度来实现参数的加解密。
其次,也感谢这位这篇文章 :http://blog.csdn.net/zr940326/article/details/51549310
技术性人员就是不喜欢多啰嗦,直接来看代码吧。
首先要了解这个东西 -------- ConverterFactory。
这是retrofit 里面一个比较重要的类,他管理着request 和response ,要想实现自己需求的请求和参数,他是两者的桥梁。
(PS:retrofit 的封装是一门艺术,这里就不多讲了,基本的配置以及结合RX来实现 的文章已经很多了,自己去好好看看)
好的,接下来我们看下 Converter工厂的源码,直接从as 贴了
public interface Converter<F, T> { T convert(F var1) throws IOException; public abstract static class Factory { public Factory() { } public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { return null; } public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) { return null; } public Converter<?, String> stringConverter(Type type, Annotation[] annotations, Retrofit retrofit) { return null; } } }
三部分组成:请求 、响应、StringConverter
我们再来看看retrofit 给我提供的Converter
public final class GsonConverterFactory extends Factory { private final Gson gson; public static GsonConverterFactory create() { return create(new Gson()); } public static GsonConverterFactory create(Gson gson) { return new GsonConverterFactory(gson); } private GsonConverterFactory(Gson gson) { if(gson == null) { throw new NullPointerException("gson == null"); } else { this.gson = gson