retrofit2 - Can I use a Custom Method Annotations in Retrofit 2.0? -
in retrofit 2.0
i know it's possible handler custom param annotations in converter.factory
.
but can handler custom method annotations customannotation
in below:
@customannotation @post("someurl") observable<myresponse> dosomething(@body body);
i found way use proxy wrap service create retrofit:
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 annotations } return method.invoke(rawservice,args); } });
Comments
Post a Comment