-
Notifications
You must be signed in to change notification settings - Fork 96
Description
What happened?
I have an endpoint method with an optional argument annotated by @HeaderParam
:
@GET
@Path("/doStuff")
String doStuff(@HeaderParam("value") Optional<String> value);
I passed it the value Optional.empty()
via a JaxRsClient
:
MyService service = JaxRsClient.create(...
service.doStuff(Optional.empty())
However, the implementation of doStuff
receives the value Optional.of("")
, rather than Optional.empty()
.
There is a failing test case to show this at develop...DoronShapiro:optional-header-tests.
This behavior happens because the implementation of Java8OptionalAwareContract
serializes empty headers as an empty string, but when they are deserialized by the Java8OptionalParamConverterProvider
, it is assumed that the value will be null if empty (and that the empty string represents a non-empty value).
What did you want to happen?
The server should receive a value of Optional.empty()
for the header argument.
One solution is for the client to not include the header at all if its value is Optional.empty()
.