-
Notifications
You must be signed in to change notification settings - Fork 50
Description
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