Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify a Default value dynamically in Jersey?

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?

like image 707
Paul Nibin Avatar asked Oct 13 '11 09:10

Paul Nibin


1 Answers

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.

like image 157
Martin Matula Avatar answered Nov 01 '22 13:11

Martin Matula