on 2023 Aug 03 3:17 PM
Hi experts,
I'm working on Android with the SAP Android SDK 7.0.0
I'm trying to create a deep entity request from a JSON using the documentation (JSON Serialisation) with Online odata.
here my code :
val query = FromJSON.entity(newEntity).from(Z_API_SERVICE_ORDER_SRV_EntitiesMetadata.EntitySets.headerSet)
query.entitySet =
Z_API_SERVICE_ORDER_SRV_EntitiesMetadata.EntitySets.headerSet
query.entityType =
Z_API_SERVICE_ORDER_SRV_EntitiesMetadata.EntityTypes.header
val headerEntity =
z_API_SERVICE_ORDER_SRV_Entities.executeQuery(query).requiredEntity
return suspendCoroutine { continuation ->
z_API_SERVICE_ORDER_SRV_Entities.createEntityAsync(headerEntity,
{
val operationSuccess: Repository.SuspendOperationResult =
Repository.SuspendOperationResult.SuspendOperationSuccess(
headerEntity
)
continuation.resume(operationSuccess)
},
{ error ->
LOGGER.debug("Entity creation failed:", error)
val operationFail =
Repository.SuspendOperationResult.SuspendOperationFail(error)
continuation.resume(operationFail)
})
}
My JSON structure model is same like my entities model structure :
{
"@odata.editLink":"",
"@odata.id":"",
"@odata.readLink":"",
"CatDesc":"",
"Category":"",
"Description":"",
"PurchaseOrderByCustomer":"",
"RejectStatus":"",
"RejectStatusLong":"",
"RejectStatusShort":"",
"RequestedServiceStartDate":"",
"Schema":"",
"ServiceObjectType":"",
"ServiceOrder":"",
"ServiceOrderType":"",
"SoldToParty":"",
"Status":"",
"Attachments":[
{
"@odata.editLink":"",
"@odata.id":"",
"@odata.readLink":"",
"DocNumber":"",
"DocType":"",
"DocumentUrl":"",
"FileName":"",
"ServiceOrder":""
}
],
"Customers":[
{
"@odata.editLink":"",
"@odata.id":"",
"@odata.readLink":"",
"City":"",
"Country":"",
"Customernumber":"",
"Email":"",
"FirstName":"",
"HouseNo":"",
"LastName":"",
"PostalCode":"",
"Region":"",
"ServiceOrder":"",
"StrSuppl3":"",
"Street":"",
"TelNumber":"",
"Title":""
}
],
"Items":[
{
"@odata.editLink":"",
"@odata.id":"",
"@odata.readLink":"",
"ItemCategory":"",
"ItemDescription":"",
"ItemQty":,
"ItemSchema":"",
"ItemStatus":"",
"ItemType":"",
"OrderItem":"",
"PartnerProduct":"",
"Product":"",
"ServiceObjectType":"",
"ServiceOrder":""
}
],
"Partners":[
{
"@odata.editLink":"",
"@odata.id":"",
"@odata.readLink":"",
"AddrNp":"",
"AddrNr":"",
"City":"",
"Country":"",
"FirstName":"",
"HouseNo":"",
"LastName":"",
"PartnerFct":"",
"PartnerNumber":"",
"PostlCod1":"",
"Region":"",
"ServiceObjectType":"",
"ServiceOrder":"",
"StrSuppl3":"",
"Street":""
}
],
"Pricing":[
{
"@odata.editLink":"",
"@odata.id":"",
"@odata.readLink":"",
"Amount":,
"Application":"",
"ConditionType":"",
"Counter":"",
"Currency":"",
"OrderItem":"",
"PricingCondition":"",
"PricingItem":"",
"ServiceOrder":"",
"StepNumber":""
}
]
}
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 :
{
"__metadata" : {
"type" : "Z_API_SERVICE_ORDER_SRV.Header"
},
"CatDesc" : "",
"Category" : "",
"Description" : "",
"IrisCode" : "",
"Origin" : "ZR2",
"PurchaseOrderByCustomer" : "dummyPO",
"RejectStatus" : "",
"RejectStatusLong" : "",
"RejectStatusShort" : "",
"RequestedServiceStartDate" : "",
"Schema" : "",
"ServiceObjectType" : "Z001",
"ServiceOrder" : "",
"ServiceOrderType" : "",
"SoldToParty" : "dummy01",
"Status" : ""
}
I've expected to have my subentities itmes, pricing, attachments etc.
In debug, I can see that my entity have this data on
For example, the code below will create a good json payload :
val headerEntity = Header().apply {
serviceObjectType = "Z001"
origin = "ZR2"
soldToParty = "dummy01"
purchaseOrderByCustomer = "dummyPO"
}
headerEntity.partners = mutableListOf(Partner().apply{
partnerFct = "Y0000001"
partnerNumber = "2000209"
})
return suspendCoroutine { continuation ->
z_API_SERVICE_ORDER_SRV_Entities.createEntityAsync(headerEntity,
{
val operationSuccess: Repository.SuspendOperationResult =
Repository.SuspendOperationResult.SuspendOperationSuccess(
headerEntity
)
continuation.resume(operationSuccess)
},
{ error ->
LOGGER.debug("Entity creation failed:", error)
val operationFail =
Repository.SuspendOperationResult.SuspendOperationFail(error)
continuation.resume(operationFail)
})
}
}
The result :
{
"__metadata" : {
"type" : "Z_API_SERVICE_ORDER_SRV.Header"
},
"CatDesc" : "",
"Category" : "",
"Description" : "",
"Origin" : "ZR2",
"Partners" : [
{
"__metadata" : {
"type" : "Z_API_SERVICE_ORDER_SRV.Partner"
},
"AddrNp" : "",
"AddrNr" : "",
"City" : "",
"Country" : "",
"FirstName" : "",
"HouseNo" : "",
"LastName" : "",
"PartnerFct" : "Y0000001",
"PartnerNumber" : "2000209",
"PostlCod1" : "",
"Region" : "",
"ServiceObjectType" : "",
"ServiceOrder" : "",
"StrSuppl3" : "",
"Street" : ""
}
],
"PurchaseOrderByCustomer" : "dummyPO",
"RejectStatus" : "",
"RejectStatusLong" : "",
"RejectStatusShort" : "",
"RequestedServiceStartDate" : "",
"Schema" : "",
"ServiceObjectType" : "Z001",
"ServiceOrder" : "",
"ServiceOrderType" : "",
"SoldToParty" : "dummy01",
"Status" : ""
}
Is it possible to deserialised a json stream to create on a fly a complex deep entity ?
Thanks a lot
Yohann
Request clarification before answering.
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:
for p in header.partners { p.isNew = true }
then when you call createEntity the child partners should be considered as new (so requiring deep insert).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
61 | |
10 | |
8 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.