1
In Retrofit 2.0我可以在Retrofit 2.0中使用自定義方法註釋嗎?
我知道這可能是處理程序自定義參數註釋Converter.Factory
。
但我可以在下面的處理程序自定義方法註解像CustomAnnotation
:
@CustomAnnotation
@POST("someUrl")
Observable<MyResponse> doSomeThing(@Body body);
In Retrofit 2.0我可以在Retrofit 2.0中使用自定義方法註釋嗎?
我知道這可能是處理程序自定義參數註釋Converter.Factory
。
但我可以在下面的處理程序自定義方法註解像CustomAnnotation
:
@CustomAnnotation
@POST("someUrl")
Observable<MyResponse> doSomeThing(@Body body);
我發現,使用代理包裝服務的方式與改造創造:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://example.com/")
.build();
ApiService rawService = retrofit.create(ApiService.class);
ApiService service = (ApiService) Proxy.newProxyInstance(rawService.getClass().getClassLoader(),
rawService.getClass().getInterfaces(),
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getAnnotation(CustomAnnotation.class) != null){
//handler the Annotations
}
return method.invoke(rawService,args);
}
});