users@jersey.java.net

[Jersey] _at_DefaultValue values question

From: NBW <emailnbw_at_gmail.com>
Date: Tue, 28 Jun 2011 20:19:39 -0400

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