palantir / palantir/conjure-java-runtime
Optional headers with an empty value are converted to the empty string
@uschi2000 is already working on this.
Since Aug 13, 2018.
- Dominant language
- Java
- Stars
- 95
- Forks
- 96
- Avg merge
- 3h 38m
- Merged PRs (30d)
- 33
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 https://github.com/palantir/http-remoting/compare/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().
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.