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

Aperta
#790 9 commenti 0 reazioni 2 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@uschi2000 ci sta già lavorando.

Dal 13/8/2018.

  • #1337 di @pkoenig10 — chiusa senza merge

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

bug

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

Lingua principale
Java
Stelle
96
Fork
95
Merge medio
8m
PR unite (30g)
55

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di palantir/conjure-java-runtime

Tutte le issue di palantir/conjure-java-runtime

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.