Reputation: 431
I am having a problem figuring out as to how I can extract the data that I am getting from the uri that I've build from apache olingo. Extracting data from the $expand works with this syntax.
uri: odata/PropertyOrigin?$expand=Property1($select=Field1);$expand=Property2($select=Field1ofProperty2))
/* JSON ->
PropertyOrigin ->
Field1Origin,
Field2Origin,
NavigationProperty1 ->
Field1,
Field2,
Field3,
NavigationProperty2 ->
NavigationField1ofProperty2 <- the one I am trying to extract */
ClientEntity ce = csi.next();
String ExtractData1 = ce.getProperty("Property1").getComplexValue().get("Field1").getValue().toString();
But, when I am trying to get the data from the second $expand, I get a object null reference, because it is not hitting the right property that I am trying to interact with.
ClientEntity ce = csi.next();
String ExtractData2 = ce.getProperty("NavigationProperty1").getComplexValue().get("NavigationProperty2").getComplexValue().get("Field1ofNavigationProperty2").getValue().toString();
Note: NavigationProperty2 is a Collection
Upvotes: 2
Views: 591
Reputation: 431
I finally figured it out:
ClientEntity ce = csi.next();
ClientCollectionValue<ClientValue> ccv = ce.getProperty("NavigationProperty1")
.getComplexValue()
.get("NavigationProperty2")
.getCollectionValue();
Iterator<ClientValue> ite = ccv.iterator();
ClientValue cv = ite.next();
String extractData3 = cer.asComplex().get("Field1ofNavigationProperty2").getValue().toString();
Description: Since the NavigationProperty2 is a collection, I figured I have to use the getcollectionvalue, instead of using getvalue or getcomplexvalue, after that I placed it on the iterator then started getting the data.
Upvotes: 1