question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

odata-v2: entityBuilder().fromJson() does not recognize sub-sub entities

See original GitHub issue

Describe the bug I am on my way to create PurchaseOrders using SAP Cloud SDK and available oData EDMX file. This EDMX is coming from a custom made oData API of an R/3 ERP.

I used @sap-cloud-sdk/generator in version 2.5.0 to generate a Virtual-Data-Model first.

Within I am trying to create a PO by using the ability to create the entity by using the purchaseOrderSetApi.entityBuilder().fromJson() functionality.

Unfortunately, this is only working for direct navigation properties of the entity purchaseOrderHeaderSet, so it’s available for toPurchaseOrderItem of the PO, but not for sub-sub entities like toPurchaseOrderItmAccountAssignment of toPurchaseOrderItem.

To Reproduce myVdm.service()purchaseOrderHeaderSetApi.requestBuilder().create( myVdm.service().purchaseOrderHeaderSetApi.entityBuilder().fromJson( (entityToSendToErp as myVdm.PurchaseOrderHeaderSet) ) )

entityToSendToErp looks like something like that: {“documentNumber”:“4100000333”, “toPurchaseOrderItem”: [ {“itemNumber”:“1”,“quantity”:“90”,“toPurchaseOrderItmAccountAssignment”: [ {“glAccountNumber”:“80000000”,“costCenter”:“321110”} ] } ], “isCreate”:true}

Expected behavior I did guess, the complete json is getting used and recognized, not only properties and navigations related to the main-entity (available as SCHEMA of the entity). As “toPurchaseOrderItmAccountAssignment” is not identified as part of the SCHEMA of “purchaseOrderHeaderSet” (what’s true indeed, because it’s part of the item), it get’s added as “customField” instead.

Maybe there is another approach to deal with deep-structured json object and getting an entity created from it and I just do not know it 😉? Hint.

Analysis I debugged the scenario and discovered file “@sap-cloud-sdk/odata-common/entity-builder”, containing method “fromJson()”. Here it does check only against the schema of the main-entity, but not of related sub-entities.

Impact / Priority This is blocking our architecture, where we’re using json objects to send to the ERP within the SDK. Affected development phase: 2 weeks before SIT Impact: Blocked Timeline: e.g. Go-Live is in 7 weeks.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
FrankEssenbergercommented, Oct 21, 2022

I would not call this a mistake because it is not clear from the fromJson() that you have to initialize something. If we keep this method in newer higher versions we either need to make this clear from the API or make it capable of initializing the object. However, we had issues with cycle references along the way.

1reaction
drvupcommented, Oct 21, 2022

Hi @FrankEssenberger , thanks for coming back to me about this issue. Yes, you’re right. I identified the lazy init stuff and I made the same mistake here again 😉

Anyhow, of course with this approach the all-time generic approach is lost. But that’s a perfect way to mitigate the issue while you and the team is checking abilities to solve the fromJson() part. Maybe it’s worth to highlight that at the documentation on the related part 😉 Lazy developers like me can identify this issue easier and maybe check out available approaches like we did discuss now 😄

However, thanks for pointing this out and thanks for the great support. This is really appreciated 😃

Best, Cedric

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid, partial json response happens when expanding an ...
Invalid, partial json response happens when expanding a contained entity with more items than the allowed PageSize for an endpoint.
Read more >
Basic Tutorial · OData - the Best Way to REST
The Open Data Protocol (OData) is a data access protocol built on core protocols like HTTP and commonly accepted methodologies like REST for...
Read more >
OData Doesn't Recognize My Collection Properties
I have narrowed it down to the OData EDM Model Configuration . How do I correctly "characterize" the collection properties (below) to the...
Read more >
Entity Relations in OData v4 Using ASP.NET Web API 2.2
OData supports creating or removing relationships between two existing entities. In OData v4 terminology, the relationship is a "reference". ( ...
Read more >
Use the OData v2 Type-safe Client API | SAP Cloud SDK
The SAP Cloud SDK supports custom fields on your entities, that are not ... The API class provides an entity builder with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found