com.sap.cloud.sdk.datamodel.odata render empty fields

p3nh2n

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 https://fasterxml.github.io/jackson-annotations/javadoc/2.7/com/fasterxml/jackson/annotation/JsonInclude.Include.html for details.

Johannes Schneider

Disclaimer: I'm part of the SAP Cloud SDK for Java development team.

Unfortunately, the SAP Cloud SDK for Java currently doesn't support excluding "empty" fields (i.e. fields with value null) for create / replace (HTTP POST / PUT) requests automatically.

We are considering adding additional APIs in the future to support such use cases.

Please also refer to this GitHub Issue for more details.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unable to access private classes in com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces

From Dev

S/4HANA Cloud SDK :com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces does not exist

From Dev

Empty key fields for MaterialBOMItem of API_BILL_OF_MATERIAL_SRV Version 2 using SAP Cloud SDK JavaScript

From Java

SAP Cloud SDK method for output service in OData form

From Dev

How to execute integrationtests for own OData service in SAP Cloud SDK

From Dev

How do I access OData service using the SAP S/4HANA Cloud SDK in existing application?

From Java

Send POST request to OData service using SAP Cloud SDK version 3.2.0

From Java

How to avoid a DestinationAccessException when sending a POST request to an OData service using SAP Cloud SDK version 3.2.0

From Dev

OData navigation returns exception when using SAP APM and S/4HANA Cloud SDK

From Dev

Use SAP Cloud SDK to integrate with a custom backend service (oData) based on VDM Generator

From Dev

SAP Cloud SDK JavaScript URL encoding ODATA filter (API_PRODUCT_SRV)

From Dev

SAP Cloud SDK for Javascript: difference between pre-delivered OData services VS self-generated clients

From Dev

SAP Java SDK OData results are sometimes multiplied

From Java

Unable to load servlet filter class: com.sap.cloud.sdk.cloudplatform.security.servlet.HttpSecurityHeadersFilter (SCP Neo)

From Dev

Found class com.sap.cloud.sdk.cloudplatform.naming.JndiLookupFacade, but interface was expected

From Dev

Securing a JS application built with SAP Cloud SDK

From Dev

SAP Cloud SDK Spring Security JARS

From Dev

SAP Cloud SDK for javascript using the destination

From Java

Perform filter on expanded entity with SAP Cloud SDK

From Dev

Root cause & Propagation of Exception in SAP Cloud SDK

From Dev

Maven Build Failure releated to com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin

From Dev

OData WCF Service Self Updating DataModel

From Dev

Dependency conflicts between SAP-Cloud-SDK and SAP cloud-security-xsuaa-integration

From Java

How to fix a DestinationAccessException thrown by the SAP Cloud SDK during application startup

From Dev

Principal Propagation is not working in the latest version of SAP Cloud SDK

From Dev

How to get user info and authorities in SAP Cloud SDK 3.0 and above

From Dev

Getting JSON parser error when using sap-cloud-sdk

From Dev

Is the SAP Cloud SDK VDM Generator handling EDMX annotations correctly?

From Dev

SAP Cloud SDK JavaScript: No CSRF Token for onPremise destination with Location ID

Related Related

  1. 1

    Unable to access private classes in com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces

  2. 2

    S/4HANA Cloud SDK :com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces does not exist

  3. 3

    Empty key fields for MaterialBOMItem of API_BILL_OF_MATERIAL_SRV Version 2 using SAP Cloud SDK JavaScript

  4. 4

    SAP Cloud SDK method for output service in OData form

  5. 5

    How to execute integrationtests for own OData service in SAP Cloud SDK

  6. 6

    How do I access OData service using the SAP S/4HANA Cloud SDK in existing application?

  7. 7

    Send POST request to OData service using SAP Cloud SDK version 3.2.0

  8. 8

    How to avoid a DestinationAccessException when sending a POST request to an OData service using SAP Cloud SDK version 3.2.0

  9. 9

    OData navigation returns exception when using SAP APM and S/4HANA Cloud SDK

  10. 10

    Use SAP Cloud SDK to integrate with a custom backend service (oData) based on VDM Generator

  11. 11

    SAP Cloud SDK JavaScript URL encoding ODATA filter (API_PRODUCT_SRV)

  12. 12

    SAP Cloud SDK for Javascript: difference between pre-delivered OData services VS self-generated clients

  13. 13

    SAP Java SDK OData results are sometimes multiplied

  14. 14

    Unable to load servlet filter class: com.sap.cloud.sdk.cloudplatform.security.servlet.HttpSecurityHeadersFilter (SCP Neo)

  15. 15

    Found class com.sap.cloud.sdk.cloudplatform.naming.JndiLookupFacade, but interface was expected

  16. 16

    Securing a JS application built with SAP Cloud SDK

  17. 17

    SAP Cloud SDK Spring Security JARS

  18. 18

    SAP Cloud SDK for javascript using the destination

  19. 19

    Perform filter on expanded entity with SAP Cloud SDK

  20. 20

    Root cause & Propagation of Exception in SAP Cloud SDK

  21. 21

    Maven Build Failure releated to com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin

  22. 22

    OData WCF Service Self Updating DataModel

  23. 23

    Dependency conflicts between SAP-Cloud-SDK and SAP cloud-security-xsuaa-integration

  24. 24

    How to fix a DestinationAccessException thrown by the SAP Cloud SDK during application startup

  25. 25

    Principal Propagation is not working in the latest version of SAP Cloud SDK

  26. 26

    How to get user info and authorities in SAP Cloud SDK 3.0 and above

  27. 27

    Getting JSON parser error when using sap-cloud-sdk

  28. 28

    Is the SAP Cloud SDK VDM Generator handling EDMX annotations correctly?

  29. 29

    SAP Cloud SDK JavaScript: No CSRF Token for onPremise destination with Location ID

HotTag

Archive