users@jax-rs-spec.java.net

[jax-rs-spec users] default value in query params

From: Marcos Luna <marcos.luna_at_email.com>
Date: Sun, 16 Aug 2015 03:20:48 +0200
 
I had to deal with a not so clear behavior in the current JAXRS specification
 
 
@Path("/myrequest")
@POST
@Consumes({MediaType.TEXT_PLAIN})
public Response method(@DefaultValue("mike") @QueryParam("name") String name, @DefaultValue("0") @PathParam("age") Integer age) {
...
} 
I knew that if some of the parameters is not received
 
        .../myrequest?name=jack&age=20
 
you get the default value instead so if I call myrequest without parameters I'll get "name" and 0 as String and Integer values respectively
 
Now, if the method is invoked like
 
.../myrequest?name=jack&age=null
 
The default value is never aplied and you will get a 404 Not Found error, why is htis?  What it forced me to do as a quick fix was to declare age parameter as String and do the casting manually with an extra check.
 
After a detailed review of the documentation I found this behavior.
 
I really would like to have a default value being used if the Type cast is not possible instead of a non informative 404 error.
 
Please share your ideas about it
 
--------------
Marcos Luna Yela