2016-07-19 4 views
1

In Retrofit 2.0Retrofit 2.0でカスタムメソッド注釈を使用できますか?

ハンドブックのカスタムParam AnnotationsがConverter.Factoryにある可能性があります。

しかし、私は以下でCustomAnnotationのようなメソッドの注釈カスタムハンドラ・ことができます。

@CustomAnnotation 
@POST("someUrl") 
Observable<MyResponse> doSomeThing(@Body body); 

答えて

0

私がサービスをラップするプロキシを使用する方法を見つけたが、改修を作成します。

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); 
        } 
       }); 
関連する問題