com.sap.cloud.sdk.datamodel.odata omit empty fields on serialisation
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
com.sap.cloud.sdk.datamodel.odata.helper.FluentHelperUpdate.executeRequest() から開始し、更新リクエスト用に OData エンティティがどのようにシリアライズされるかを調べます。既存の excludingFields() による回避策と要求された動作を比較します。null フィールドを手動で列挙せずに省略でき、null ではない値と false の値は引き続きシリアライズされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Hi all!
In the context of an OData update request we run into an error response from the SAP service called. We are using com.sap.cloud.sdk.datamodel:odata-core in version 3.65.0. The Method in Question is com.sap.cloud.sdk.datamodel.odata.helper.FluentHelperUpdate.executeRequest().
When serializing in REST calls with data from com.sap.cloud.sdk.datamodel.odata, empty fields are also rendered into the output:
{
"insuranceId" : "ABC123",
"terminationDate" : null,
"terminationReason" : "UNKNOWN",
"terminationWish" : null,
"terminationReceived" : "/Date(1648027328522)/",
"force" : false
}
This fails on the SAP side with HttpResult 400 - bad request, because these fields are either not allowed to be empty or not allowed to be included at all.
We are now looking for a way / a setting to prevent this, so that something like
{
"insuranceId" : "ABC123",
"terminationReason" : "UNKNOWN",
"terminationReceived" : "/Date(1648027328522)/",
"force" : false
}
is rendered out.
As a workaround, we are using com.sap.cloud.sdk.datamodel.odata.helper.FluentHelperUpdate.excludingFields() right now as follows.
final var emptyEntityFields = new ArrayList<EntityField>();
if(cancellation.getTerminationDate() == null) emptyEntityFields.add(new EntityField("terminationDate"));
if(cancellation.getTerminationWish() == null) emptyEntityFields.add(new EntityField("terminationWish"));
this.dmeEpaService.updateTerminationRequest(terminationRequest)
.replacingEntity()
.excludingFields(emptyEntityFields.toArray(EntityField[]::new))
.executeRequest(this.httpDestination);
This workaround is cumbersome and needed on every request affected. As an example, in the jackson environment there is the setting @JsonInclude(JsonInclude.Include.NON_NULL) to accomplish this for every entity class annotated that way. See com.fasterxml.jackson.annotation
Enum JsonInclude.Include.NON_NULL for details an an eample.
Thanks in advance and best regards
Peter Hahn
- 主要言語
- HTML
- スター
- 52
- フォーク
- 57
- 平均マージ
- 2日 1時間
- マージ済み PR(30日)
- 20
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
SAP/cloud-sdk のほかの issue
-
Docs: 2 broken linksオープン
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 45/100
SAP/cloud-sdk#1861 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
feedback
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
SAP/cloud-sdk#1829 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ROCm/rocm-libraries#15866 ·
メンテナーはふだん 2 日以内に返信
-
area: web
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
inabagumi/shinju-date#6823 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
ManageSieve proxy: a backend's NO/BYE greeting is skipped as a capability line and reported as EOFオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
dmtrKovalenko/odiff#191 ·