【问题标题】:How can I extract data from multiple nested expand from ODATA using OLINGO?如何使用 OLINGO 从 ODATA 的多个嵌套扩展中提取数据?
【发布时间】:2019-06-04 15:01:10
【问题描述】:

我在弄清楚如何从 Apache olingo 构建的 uri 中提取数据时遇到问题。从 $expand 中提取数据使用这种语法。

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();

但是,当我尝试从第二个 $expand 获取数据时,我得到了一个对象空引用,因为它没有触及我尝试与之交互的正确属性。

ClientEntity ce = csi.next();
String ExtractData2 = ce.getProperty("NavigationProperty1").getComplexValue().get("NavigationProperty2").getComplexValue().get("Field1ofNavigationProperty2").getValue().toString();

注意: NavigationProperty2 是一个集合

【问题讨论】:

    标签: java apache nested odata olingo


    【解决方案1】:

    我终于明白了:

     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();
    

    描述:由于 NavigationProperty2 是一个集合,我想我必须使用 getcollectionvalue,而不是使用 getvalue 或 getcomplexvalue,然后我将它放在迭代器上然后开始获取数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-09
      相关资源
      最近更新 更多