users@jersey.java.net

[Jersey] Re: _at_DefaultValue values question

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 30 Jun 2011 09:11:30 +0200

Hi Noah,

@javax.ws.rs.DefaultValue annotation comes from JAX-RS.
We can not do much in Jersey about this.

You might want to ask for an improvement for this area at [1],
although i am not sure what can be done there given how annotation
members are restricted in Java (compile-type constants, only limited
number of types allowed).

~Jakub

[1]http://java.net/projects/jax-rs-spec/


On 06/29/2011 02:19 AM, NBW wrote:
> Tonight I was trying to set a @DefaultValue for a @QueryParam and I wanted to use an enum, eg. Status.COMPLETE. The enum Status is set as the type of the QueryParam. I tried something like this:
>
> ...(@DefaultValue(Status.COMPLETE) @QueryParam("status") Status status) {
>
> The first problem was it insisted the @Default value be a String. So I said OK, and changed it to:
>
> ...(@DefaultValue(Status.COMPLETE.toString()) @QueryParam("status") Status status) {
>
> Next is complained that the value had to be a constant. Well in the case of the enum I thought that toString() is effectively a constant value. So there's that issue, but I would really like to simply be able to use an enum value when the type of the QueryParam is an enum which is what I originally tried going with in the first example above.
>
> Am I perhaps missing something or is this the current state of things in this regard and I have to work around it with something like this where I explicitly set the Default value to the string corresponding to the enum value I want to be default:
>
> ...(@DefaultValue("COMPLETE") @QueryParam("status") Status status) {
>
> Thanks,
>
> -Noah
>
>