Skip to content

Optional headers with an empty value are converted to the empty string #790

@DoronShapiro

Description

@DoronShapiro

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().

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions