I am using Java Jersey library to create RESTful web service.
I am using query param for method. I want to specify the Default value for that query param. If I specify a constant string, then it is fine. But how can I specify a runtime value as the default value?
import javax.ws.rs.DefaultValue; 
import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.Produces; 
import javax.ws.rs.QueryParam; 
import javax.ws.rs.core.MediaType; 
@Path( "Hello" ) 
public class HelloWorld 
{ 
    private String defaultValue = "Default"; 
    @GET 
    @Produces( MediaType.APPLICATION_XML ) 
    public String greet( @QueryParam( "User" ) @DefaultValue( "defaultValue" )String userName ) 
    { 
        String returnValue = "Hello " + userName; 
        System.out.println( returnValue ); 
        return returnValue; 
    } 
} 
Instead of a constant how can I use a variable here? Is it possible at all?
No, it is not possible - at least not using the annotation. Can you say more about why you need to do that? Maybe I can then suggest some alternative approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With