com.sap.cloud.sdk.datamodel.odata omit empty fields on serialisation

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

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

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java
領域
api

調査の方向性

com.sap.cloud.sdk.datamodel.odata.helper.FluentHelperUpdate.executeRequest() から開始し、更新リクエスト用に OData エンティティがどのようにシリアライズされるかを調べます。既存の excludingFields() による回避策と要求された動作を比較します。null フィールドを手動で列挙せずに省略でき、null ではない値と false の値は引き続きシリアライズされれば完了です。

索引モデルが issue の本文から書いたものです。

説明

enhancement feature request Java waiting for release

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

環境構築

はじめの一歩

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

SAP/cloud-sdk のほかの issue

SAP/cloud-sdk の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

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

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