https://kotlinlang.org logo
Title
o

Omar Ahmed

03/03/2020, 9:50 AM
Hi, I built a small library for Android, it helps you to add custom annotations on retrofit calls and retrieve them later via interceptor Check it out and give me your feedback https://t.co/FF72E0GR1s
👀 1
🙂 1
👍 1
t

trevjones

03/03/2020, 3:48 PM
I think there is an easier way. but i have not played with it yet. Retrofit adds an implicit
Tag
called
Invocation
that has a reference to the
Method
at which point you can query for custom annotations via the normal reflection api's. All of which can be done in an interceptor without the need for a custom call adapter factory.
Been meaning to POC this out. let me see what I can throw together today and i'll post back here
👍 1
single base class that is pretty damn simple. then the test file has an example use-case
something wrong in the way I am mutating the request but proves that it at least picked up the annotation and tried to muck with it
o

Omar Ahmed

03/04/2020, 11:41 AM
very cool that's a better and simpler way to do it 👏
i wasn't aware that retrofit add
Invocation
Tag to all its requests
t

trevjones

03/04/2020, 5:13 PM
I knew about tag. but Jesse wilson is who got me thinking about how to do some of this easier. https://twitter.com/jessewilson/status/1231569857986035712
only other note i'd add about that, is the call to
Method.getAnnotation(Class<T>)
might be expensive and worth caching in a map. ie
val annotationCache: MutableMap<Method, T>
where T is the annotation.
👍 1
o

Omar Ahmed

03/05/2020, 11:57 AM
yes totally agree caching annotation worth it