Surendra Gupta
Surendra Gupta

Reputation: 11

EDM DateTime field is not working as expected for the Patch call [post Cloud SDK version upgrade]

We upgraded to cloud SDK to the following version which is causing weird behavior for the patch call. This looks to be bug in Cloud SDK as we see the different behavior between Post & Patch for the EDM DateTime. Could you please confirm if this a bug.

In the Odata service, the property definition is this

<Property Name="DeliveryDate" Type="Edm.DateTime" Precision="0" sap:display-format="Date" sap:label="Delivery date" sap:quickinfo="Item delivery date" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>

In the VDM, the same property is defined as

 @SerializedName("DeliveryDate")
    @JsonProperty("DeliveryDate")
    @Nullable
    @JsonSerialize(using = com.sap.cloud.sdk.s4hana.datamodel.odata.adapter.JacksonLocalDateTimeSerializer.class)
    @JsonDeserialize(using = com.sap.cloud.sdk.s4hana.datamodel.odata.adapter.JacksonLocalDateTimeDeserializer.class)
    @JsonAdapter(com.sap.cloud.sdk.s4hana.datamodel.odata.adapter.LocalDateTimeAdapter.class)
    @ODataField(odataName = "DeliveryDate", converter = com.sap.cloud.sdk.s4hana.datamodel.odata.adapter.LocalDateTimeCalendarConverter.class)
    private LocalDateTime deliveryDate;

Version: <cloud-sdk.version>3.34.0</cloud-sdk.version>

Is the OData Service a Version 2.0 ? Yes, OData 2.0(OdataV2)

Exact payload for both the cases ?

Payload and code invocation for Create:

{
        "Quantity": 2,
        "Price": 20,
        "UnitOfMeasure": "EA",      
        "DeliveryDate": "2020-03-23T07:16:23Z"    
}

code invocation

ItemCDSViewForGuidedBuying item = new ItemCDSViewForGuidedBuying();

// with some setter fields... 

item = s4ReqService.createItemCDSViewForGuidedBuying(item)
          .asChildOf(header, HeaderCDSForPRForGuidedBuying.TO_PURCHASEREQUISITIONITEM_WD)
          .withHeader(HttpHeaders.ACCEPT_LANGUAGE, requestContext.getAcceptLanguages())
          .executeRequest(getS4Destination())
          .getModifiedEntity(); 

Payload and code invocation for Update:

{
"DeliveryDate": "2020-09-18T07:16:23Z"        
}

code invocation

   ItemCDSViewForGuidedBuying item = new ItemCDSViewForGuidedBuying();
    
    // with some setter fields...
    
    s4ReqService.updateItemCDSViewForGuidedBuying(item)
              .modifyingEntity()
              .withHeader(HttpHeaders.ACCEPT_LANGUAGE, requestContext.getAcceptLanguages())
              .executeRequest(getS4Destination()); 

Please confirm whether or not the modules s4hana-all or s4hana-connectivity are part of your dependencies?

Yes, s4hana-connectivity is part of it along with following dependencies

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.sap.cloud.sdk</groupId>
            <artifactId>sdk-bom</artifactId>
            <version>3.34.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Few other dependencies in the POM.xml

<dependency>
    <groupId>com.sap.cloud.sdk.datamodel</groupId>
    <artifactId>odata-core</artifactId>
</dependency>
<dependency>
    <groupId>com.sap.cloud.sdk.s4hana</groupId>
    <artifactId>s4hana-connectivity</artifactId>
</dependency>

For Create entity call : Post Call ODataEntitySerializer.serializeEntityForCreate() when this is called, the Date field value goes as expected to the back-end something like this: 2020-08-18T07:16:23 and works as expected. Cloud SDK uses the following code to generate the request payload :

final JsonObject jsonObject = GSON.toJsonTree(entity).getAsJsonObject();

For Patch call: Does not work ODataEntitySerializer.serializeEntityForUpdatePatch() when this is called, the Date field value goes incorrectly. If we enable the gateway trace in the s4 system, we receive the payload like the below one which is incorrect in terms of OData Edm.DateTime.

"DeliveryDate":{"date":{"year":2020,"month":9,"day":18},"time":{"hour":7,"minute":16,"second":23,"nano":0}}

Cloud SDK uses the following code to generate the patch payload which is producing incorrect value :

final JsonObject o = Objects.requireNonNull((JsonObject) serializeComplexValue(patchValues, parentObjects));

Stacktrace:

owns: NioEndpoint$NioSocketWrapper  (id=14260)  
    ODataEntitySerializer$PatchSerializerHelper.toJson() line: 139  
    ODataEntitySerializer.serializeEntityForUpdatePatch(VdmEntity<?>, Collection<FieldReference>) line: 106 
    ItemCDSViewForGuidedBuyingUpdateFluentHelper(FluentHelperUpdate<FluentHelperT,EntityT>).getSerializedEntity() line: 421 
    ItemCDSViewForGuidedBuyingUpdateFluentHelper(FluentHelperUpdate<FluentHelperT,EntityT>).toRequest() line: 384   
    ItemCDSViewForGuidedBuyingUpdateFluentHelper(FluentHelperUpdate<FluentHelperT,EntityT>).executeRequest(HttpDestinationProperties) line: 372 
    S4RequisitionSourceImpl.updateReqLineItem(UUID, RequisitionItems) line: 239 
    

Let us know the resolution or workaround for the same.

Upvotes: 0

Views: 697

Answers (1)

Emdee
Emdee

Reputation: 1693

This seems to be a bug in the SAP Cloud SDK, we're investigating this issue.

SAP Cloud SDK 3.36.0 fixes this issue. Please update the Cloud SDK version in your application. Refer to the release notes for further reference.

Upvotes: 0

Related Questions