Marcos,
The behavior that you described is correct, and in line with the specification. Naturally, the string “null” cannot be converted to an Integer. I believe that this is resulting in an IllegalArgumentException which is then converted to a 404.
If you want a different behavior, you should consider providing your own ParamConverter. See also ParamConverterProvider for more information.
— Santiago
> On Aug 15, 2015, at 9:20 PM, Marcos Luna <marcos.luna_at_email.com> wrote:
>
>
> 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