<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: SAP Android SDK : Create deep entity from json deserialization in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/sap-android-sdk-create-deep-entity-from-json-deserialization/qaa-p/12750413#M4785779</link>
    <description>&lt;P&gt;Hi Evan and thanks a lot for your quick answer.&lt;/P&gt;&lt;P&gt;Your solution works :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;headerEntity.unsetDataValue(Header.serviceOrder)&lt;BR /&gt;headerEntity.isNew = true&lt;BR /&gt;headerEntity.partners = headerEntity.partners.map {&lt;BR /&gt;    it.isNew = true&lt;BR /&gt;    it&lt;BR /&gt;}.toMutableList()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks again&lt;/P&gt;</description>
    <pubDate>Fri, 04 Aug 2023 09:05:02 GMT</pubDate>
    <dc:creator>yohann_weberfr</dc:creator>
    <dc:date>2023-08-04T09:05:02Z</dc:date>
    <item>
      <title>SAP Android SDK : Create deep entity from json deserialization</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-android-sdk-create-deep-entity-from-json-deserialization/qaq-p/12750411</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;
  &lt;P&gt;I'm working on Android with the SAP Android SDK 7.0.0&lt;/P&gt;
  &lt;P&gt;I'm trying to create a deep entity request from a JSON using the documentation (&lt;A href="https://help.sap.com/doc/f53c64b93e5140918d676b927a3cd65b/Cloud/en-US/docs-en/guides/features/backend-connectivity/android/using-odata-api.html#json-serialization" target="_blank"&gt;JSON Serialisation&lt;/A&gt;) with Online odata.&lt;/P&gt;
  &lt;P&gt;here my code :&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;PRE&gt;&lt;CODE&gt;val query = FromJSON.entity(newEntity).from(Z_API_SERVICE_ORDER_SRV_EntitiesMetadata.EntitySets.headerSet)&lt;BR /&gt; query.entitySet =&lt;BR /&gt;     Z_API_SERVICE_ORDER_SRV_EntitiesMetadata.EntitySets.headerSet&lt;BR /&gt; query.entityType =&lt;BR /&gt;     Z_API_SERVICE_ORDER_SRV_EntitiesMetadata.EntityTypes.header&lt;BR /&gt;&lt;BR /&gt;val headerEntity =&lt;BR /&gt;     z_API_SERVICE_ORDER_SRV_Entities.executeQuery(query).requiredEntity&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt; return suspendCoroutine { continuation -&amp;gt;&lt;BR /&gt;     z_API_SERVICE_ORDER_SRV_Entities.createEntityAsync(headerEntity,&lt;BR /&gt;         {&lt;BR /&gt;             val operationSuccess: Repository.SuspendOperationResult =&lt;BR /&gt;                 Repository.SuspendOperationResult.SuspendOperationSuccess(&lt;BR /&gt;                     headerEntity&lt;BR /&gt;                 )&lt;BR /&gt;             continuation.resume(operationSuccess)&lt;BR /&gt;         },&lt;BR /&gt;         { error -&amp;gt;&lt;BR /&gt;             LOGGER.debug("Entity creation failed:", error)&lt;BR /&gt;             val operationFail =&lt;BR /&gt;                 Repository.SuspendOperationResult.SuspendOperationFail(error)&lt;BR /&gt;             continuation.resume(operationFail)&lt;BR /&gt;         })&lt;BR /&gt; }&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;My JSON structure model is same like my entities model structure :&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;{&lt;BR /&gt;   "@odata.editLink":"",&lt;BR /&gt;   "@odata.id":"",&lt;BR /&gt;   "@odata.readLink":"",&lt;BR /&gt;   "CatDesc":"",&lt;BR /&gt;   "Category":"",&lt;BR /&gt;   "Description":"",&lt;BR /&gt;   "PurchaseOrderByCustomer":"",&lt;BR /&gt;   "RejectStatus":"",&lt;BR /&gt;   "RejectStatusLong":"",&lt;BR /&gt;   "RejectStatusShort":"",&lt;BR /&gt;   "RequestedServiceStartDate":"",&lt;BR /&gt;   "Schema":"",&lt;BR /&gt;   "ServiceObjectType":"",&lt;BR /&gt;   "ServiceOrder":"",&lt;BR /&gt;   "ServiceOrderType":"",&lt;BR /&gt;   "SoldToParty":"",&lt;BR /&gt;   "Status":"",&lt;BR /&gt;   "Attachments":[&lt;BR /&gt;      {&lt;BR /&gt;         "@odata.editLink":"",&lt;BR /&gt;         "@odata.id":"",&lt;BR /&gt;         "@odata.readLink":"",&lt;BR /&gt;         "DocNumber":"",&lt;BR /&gt;         "DocType":"",&lt;BR /&gt;         "DocumentUrl":"",&lt;BR /&gt;         "FileName":"",&lt;BR /&gt;         "ServiceOrder":""&lt;BR /&gt;      }&lt;BR /&gt;   ],&lt;BR /&gt;   "Customers":[&lt;BR /&gt;      {&lt;BR /&gt;         "@odata.editLink":"",&lt;BR /&gt;         "@odata.id":"",&lt;BR /&gt;         "@odata.readLink":"",&lt;BR /&gt;         "City":"",&lt;BR /&gt;         "Country":"",&lt;BR /&gt;         "Customernumber":"",&lt;BR /&gt;         "Email":"",&lt;BR /&gt;         "FirstName":"",&lt;BR /&gt;         "HouseNo":"",&lt;BR /&gt;         "LastName":"",&lt;BR /&gt;         "PostalCode":"",&lt;BR /&gt;         "Region":"",&lt;BR /&gt;         "ServiceOrder":"",&lt;BR /&gt;         "StrSuppl3":"",&lt;BR /&gt;         "Street":"",&lt;BR /&gt;         "TelNumber":"",&lt;BR /&gt;         "Title":""&lt;BR /&gt;      }&lt;BR /&gt;   ],&lt;BR /&gt;   "Items":[&lt;BR /&gt;      {&lt;BR /&gt;         "@odata.editLink":"",&lt;BR /&gt;         "@odata.id":"",&lt;BR /&gt;         "@odata.readLink":"",&lt;BR /&gt;         "ItemCategory":"",&lt;BR /&gt;         "ItemDescription":"",&lt;BR /&gt;         "ItemQty":,&lt;BR /&gt;         "ItemSchema":"",&lt;BR /&gt;         "ItemStatus":"",&lt;BR /&gt;         "ItemType":"",&lt;BR /&gt;         "OrderItem":"",&lt;BR /&gt;         "PartnerProduct":"",&lt;BR /&gt;         "Product":"",&lt;BR /&gt;         "ServiceObjectType":"",&lt;BR /&gt;         "ServiceOrder":""&lt;BR /&gt;      }&lt;BR /&gt;   ],&lt;BR /&gt;   "Partners":[&lt;BR /&gt;      {&lt;BR /&gt;         "@odata.editLink":"",&lt;BR /&gt;         "@odata.id":"",&lt;BR /&gt;         "@odata.readLink":"",&lt;BR /&gt;         "AddrNp":"",&lt;BR /&gt;         "AddrNr":"",&lt;BR /&gt;         "City":"",&lt;BR /&gt;         "Country":"",&lt;BR /&gt;         "FirstName":"",&lt;BR /&gt;         "HouseNo":"",&lt;BR /&gt;         "LastName":"",&lt;BR /&gt;         "PartnerFct":"",&lt;BR /&gt;         "PartnerNumber":"",&lt;BR /&gt;         "PostlCod1":"",&lt;BR /&gt;         "Region":"",&lt;BR /&gt;         "ServiceObjectType":"",&lt;BR /&gt;         "ServiceOrder":"",&lt;BR /&gt;         "StrSuppl3":"",&lt;BR /&gt;         "Street":""&lt;BR /&gt;      }&lt;BR /&gt;   ],&lt;BR /&gt;   "Pricing":[&lt;BR /&gt;      {&lt;BR /&gt;         "@odata.editLink":"",&lt;BR /&gt;         "@odata.id":"",&lt;BR /&gt;         "@odata.readLink":"",&lt;BR /&gt;         "Amount":,&lt;BR /&gt;         "Application":"",&lt;BR /&gt;         "ConditionType":"",&lt;BR /&gt;         "Counter":"",&lt;BR /&gt;         "Currency":"",&lt;BR /&gt;         "OrderItem":"",&lt;BR /&gt;         "PricingCondition":"",&lt;BR /&gt;         "PricingItem":"",&lt;BR /&gt;         "ServiceOrder":"",&lt;BR /&gt;         "StepNumber":""&lt;BR /&gt;      }&lt;BR /&gt;   ]&lt;BR /&gt;}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;but when i'm tracing my request in my SAP on-premise system, I have only the "first level", the header data. None of my sub-entity was transferred. You can see the result :&lt;/P&gt;
  &lt;P&gt;{&lt;BR /&gt; "__metadata" : {&lt;BR /&gt; "type" : "Z_API_SERVICE_ORDER_SRV.Header"&lt;BR /&gt; },&lt;BR /&gt; "CatDesc" : "",&lt;BR /&gt; "Category" : "",&lt;BR /&gt; "Description" : "",&lt;BR /&gt; "IrisCode" : "",&lt;BR /&gt; "Origin" : "ZR2",&lt;BR /&gt; "PurchaseOrderByCustomer" : "dummyPO",&lt;BR /&gt; "RejectStatus" : "",&lt;BR /&gt; "RejectStatusLong" : "",&lt;BR /&gt; "RejectStatusShort" : "",&lt;BR /&gt; "RequestedServiceStartDate" : "",&lt;BR /&gt; "Schema" : "",&lt;BR /&gt; "ServiceObjectType" : "Z001",&lt;BR /&gt; "ServiceOrder" : "",&lt;BR /&gt; "ServiceOrderType" : "",&lt;BR /&gt; "SoldToParty" : "dummy01",&lt;BR /&gt; "Status" : ""&lt;BR /&gt;}&lt;/P&gt;
  &lt;P&gt;I've expected to have my subentities itmes, pricing, attachments etc.&lt;/P&gt;
  &lt;P&gt;In debug, I can see that my entity have this data on &lt;/P&gt;
  &lt;P&gt;For example, the code below will create a good json payload :&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;val headerEntity = Header().apply {&lt;BR /&gt;            serviceObjectType = "Z001"&lt;BR /&gt;            origin = "ZR2"&lt;BR /&gt;            soldToParty = "dummy01"&lt;BR /&gt;            purchaseOrderByCustomer = "dummyPO"&lt;BR /&gt;    }&lt;BR /&gt;&lt;BR /&gt;    headerEntity.partners = mutableListOf(Partner().apply{&lt;BR /&gt;        partnerFct = "Y0000001"&lt;BR /&gt;        partnerNumber = "2000209"&lt;BR /&gt;    })&lt;BR /&gt;    return suspendCoroutine { continuation -&amp;gt;&lt;BR /&gt;        z_API_SERVICE_ORDER_SRV_Entities.createEntityAsync(headerEntity,&lt;BR /&gt;            {&lt;BR /&gt;                val operationSuccess: Repository.SuspendOperationResult =&lt;BR /&gt;                    Repository.SuspendOperationResult.SuspendOperationSuccess(&lt;BR /&gt;                        headerEntity&lt;BR /&gt;                    )&lt;BR /&gt;                continuation.resume(operationSuccess)&lt;BR /&gt;            },&lt;BR /&gt;            { error -&amp;gt;&lt;BR /&gt;                LOGGER.debug("Entity creation failed:", error)&lt;BR /&gt;                val operationFail =&lt;BR /&gt;                    Repository.SuspendOperationResult.SuspendOperationFail(error)&lt;BR /&gt;                continuation.resume(operationFail)&lt;BR /&gt;            })&lt;BR /&gt;    }&lt;BR /&gt;}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt; The result : &lt;/P&gt;
  &lt;P&gt;{&lt;BR /&gt; "__metadata" : {&lt;BR /&gt; "type" : "Z_API_SERVICE_ORDER_SRV.Header"&lt;BR /&gt; },&lt;BR /&gt; "CatDesc" : "",&lt;BR /&gt; "Category" : "",&lt;BR /&gt; "Description" : "",&lt;BR /&gt; "Origin" : "ZR2",&lt;BR /&gt; "Partners" : [&lt;BR /&gt; {&lt;BR /&gt; "__metadata" : {&lt;BR /&gt; "type" : "Z_API_SERVICE_ORDER_SRV.Partner"&lt;BR /&gt; },&lt;BR /&gt; "AddrNp" : "",&lt;BR /&gt; "AddrNr" : "",&lt;BR /&gt; "City" : "",&lt;BR /&gt; "Country" : "",&lt;BR /&gt; "FirstName" : "",&lt;BR /&gt; "HouseNo" : "",&lt;BR /&gt; "LastName" : "",&lt;BR /&gt; "PartnerFct" : "Y0000001",&lt;BR /&gt; "PartnerNumber" : "2000209",&lt;BR /&gt; "PostlCod1" : "",&lt;BR /&gt; "Region" : "",&lt;BR /&gt; "ServiceObjectType" : "",&lt;BR /&gt; "ServiceOrder" : "",&lt;BR /&gt; "StrSuppl3" : "",&lt;BR /&gt; "Street" : ""&lt;BR /&gt; }&lt;BR /&gt; ],&lt;BR /&gt; "PurchaseOrderByCustomer" : "dummyPO",&lt;BR /&gt; "RejectStatus" : "",&lt;BR /&gt; "RejectStatusLong" : "",&lt;BR /&gt; "RejectStatusShort" : "",&lt;BR /&gt; "RequestedServiceStartDate" : "",&lt;BR /&gt; "Schema" : "",&lt;BR /&gt; "ServiceObjectType" : "Z001",&lt;BR /&gt; "ServiceOrder" : "",&lt;BR /&gt; "ServiceOrderType" : "",&lt;BR /&gt; "SoldToParty" : "dummy01",&lt;BR /&gt; "Status" : ""&lt;BR /&gt;}&lt;/P&gt;
  &lt;P&gt;Is it possible to deserialised a json stream to create on a fly a complex deep entity ?&lt;/P&gt;
  &lt;P&gt;Thanks a lot&lt;/P&gt;
  &lt;P&gt;Yohann &lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 14:17:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-android-sdk-create-deep-entity-from-json-deserialization/qaq-p/12750411</guid>
      <dc:creator>yohann_weberfr</dc:creator>
      <dc:date>2023-08-03T14:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAP Android SDK : Create deep entity from json deserialization</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-android-sdk-create-deep-entity-from-json-deserialization/qaa-p/12750412#M4785778</link>
      <description>&lt;P&gt;After using FromJSON.entity, the returned entity's children will all have "isNew" of false. Because we assume the values already existed somewhere since they were deserialized from JSON. Try this:&lt;/P&gt;&lt;P&gt;    for p in header.partners { p.isNew = true }&lt;/P&gt;&lt;P&gt;then when you call createEntity the child partners should be considered as new (so requiring deep insert).&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 21:06:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-android-sdk-create-deep-entity-from-json-deserialization/qaa-p/12750412#M4785778</guid>
      <dc:creator>evanireland</dc:creator>
      <dc:date>2023-08-03T21:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAP Android SDK : Create deep entity from json deserialization</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-android-sdk-create-deep-entity-from-json-deserialization/qaa-p/12750413#M4785779</link>
      <description>&lt;P&gt;Hi Evan and thanks a lot for your quick answer.&lt;/P&gt;&lt;P&gt;Your solution works :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;headerEntity.unsetDataValue(Header.serviceOrder)&lt;BR /&gt;headerEntity.isNew = true&lt;BR /&gt;headerEntity.partners = headerEntity.partners.map {&lt;BR /&gt;    it.isNew = true&lt;BR /&gt;    it&lt;BR /&gt;}.toMutableList()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 09:05:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-android-sdk-create-deep-entity-from-json-deserialization/qaa-p/12750413#M4785779</guid>
      <dc:creator>yohann_weberfr</dc:creator>
      <dc:date>2023-08-04T09:05:02Z</dc:date>
    </item>
  </channel>
</rss>

