users@jersey.java.net

[Jersey] Re: Supporting Optional arguments

From: Santiago Pericas-Geertsen <Santiago.PericasGeertsen_at_oracle.com>
Date: Mon, 24 Nov 2014 09:29:21 -0500

On Nov 23, 2014, at 10:39 AM, Andreas Lundblad <andreas.lundblad_at_gmail.com> wrote:

> If a request is made to a resource method, but one of its arguments is missing, Jersey accepts the request (if the parameter is of a reference type) and calls the method and fills in the missing arguments with 'null'.
>
> I often find it frustrating to deal with null values so I've come to do a lot of
>
> Optional<String> optArg1 = Optional.ofNullable(arg1);
> Optional<String> optArg2 = Optional.ofNullable(arg2);
> ...
>
> at the top of my resource methods.
>
> Has there been any discussion on adding support for Optional as argument type directly in Jersey?

 Not that I'm aware of. Note that Optional is a JDK 8 class. You may want to file an RFE for JAX-RS 2.1 which will depend on that version of the JDK.

https://java.net/jira/browse/JAX_RS_SPEC/

-- Santiago