play-jaxrs icon indicating copy to clipboard operation
play-jaxrs copied to clipboard

@QueryParam for integer types throws exception

Open dim-s opened this issue 11 years ago • 4 comments

I'm trying to use @QueryParam annotation for integer type for example, and get a cast exception.

public Result index(@QueryParam("id") Option<Integer> idParam){
     Integer id = idParam.get(); // here will throw the exception
}

I think that for other types throws exception.

P.S. I think that in the case of really type casting errors instance of Option need to return null.

dim-s avatar Jul 17 '13 16:07 dim-s

Basically, there is no special treatment for different types. URL is parsed as String right now. So QueryParam needs to be Option<String>

pk11 avatar Jul 29 '13 00:07 pk11

Also, this is from the readme: "the captured field can only be a String i.e."

pk11 avatar Jul 29 '13 00:07 pk11

Sometimes it's not convenient for using. Also, JAX-RS Spec describes how convert string values to other basic types, from spec:

Be a primitive type Have a static method named valueOf or fromString that accepts a single String argument (see, for example, Integer.valueOf(String)) Have a constructor that accepts a single String argument

I see that play-jaxrs does not support all features of the specification, but it might be convenient to use.

dim-s avatar Jul 29 '13 05:07 dim-s

unfortunately, play-jaxrs supports only a subset of the spec right now. Depending on my schedule I will try to fill the gap, in the meantime pull requests are welcome :-)

pk11 avatar Jul 29 '13 15:07 pk11