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

オープン
#790 コメント 9 件 リアクション 0 件 担当者 2 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@uschi2000 がすでに取り組んでいます。

2018年8月13日 から。

  • #1337 @pkoenig10 による — マージされずにクローズ

評価

この issue はまだ評価されていません。

説明

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

主要言語
Java
スター
96
フォーク
95
平均マージ
8分
マージ済み PR(30日)
55

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

palantir/conjure-java-runtime のほかの issue

palantir/conjure-java-runtime の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。