I need to access the Route annotation at runtime, can you add @Retention(RetentionPolicy.RUNTIME) on the Route annotation so that it becomes available at runtime?
Here’s what I want to do to give you more context: I want to create a “sendRequest” method that takes a request as parameter and using reflection I want to inspect the Route annotation’s VERB and use correct method (get, post, put) to send the request to the server.
There’s now support for using the IGet, IPost, IPut, IDelete and IPatch interface markers on Request DTO’s, e.g:
public class SendGet : IReturn<SendVerbResponse>, IGet
{
public int Id { get; set; }
}
public class SendPut : IReturn<SendVerbResponse>, IPut
{
public int Id { get; set; }
}
Which are now used internally in the existing Send and SendAsync API’s on all Service Clients to determine which HTTP Method to use so now you can send all DTO’s using the same API’s and it will choose the appropriate HTTP method, e.g:
var response = client.Send(new SendGet { Id = 1 }); // sends with GET
var response = await client.SendAsync(new SendPut { Id = 1 }); // sends with PUT
The equivalent API’s are also available in the Java JsonServiceClient where the interfaces are now emitted in the generated Java DTO’s e.g
public static class SendGet implements IReturn<SendVerbResponse>, IGet { ... }
public static class SendPut implements IReturn<SendVerbResponse>, IPut { ... }
and works the same way as the C# client, e.g the equivalent API’s above in Java look like:
SendVerbResponse response = client.send(new SendGet().setId(1));
client.putAsync(request, new AsyncResult<HelloAllTypesResponse>() {
public void success(HelloAllTypesResponse response) { ... }
});