【发布时间】:2018-07-02 20:53:20
【问题描述】:
我正在使用 Cumulocity Java SDK,并尝试访问其中一个 ManagedObject 中的自定义片段。类似的东西:
...
"type": "sap_CustomomerLocation",
"c8y_PropertyType":{
"Customer.Name":{
"name":"customerName",
"sap_field_name":{
"requestIdentifier":"SAP",
"adressIdentifier":"customerName"
}
},
"Customer.Address":{
"name":"customerAddress",
"sap_field_name":{
"requestIdentifier":"SAP",
"adressIdentifier":"customerAddress"
}
}
}
...
我无法更改片段的格式。在 Java 应用程序中,我通过以下方式获取 Mo:
InventoryFilter filter = new InventoryFilter();
filter.byType("sap_CustomomerLocation");
ManagedObjectCollection configuration = platform.getInventoryApi().getManagedObjectsByFilter(filter);
ManagedObjectRepresentation singleConfig = configuration.get().allPages().iterator().next();
Map<String, Object> attrs = singleConfig.getAttrs();
问题是我无法访问“sap_field_name”,attrs 是一个 HashMap@Node。在 IntelliJ 的调试器中,当我使用“evaluateExpression”时,会生成类似的东西:
((HashMap.Node)((HashMap)((HashMap.Node)((HashMap)((HashMap.Node)((HashMap)((HashMap.Node)((HashMap)attrs).entrySet().toArray()[0]).getValue()).entrySet().toArray()[0]).getValue()).entrySet().toArray()[0]).getValue()).entrySet().toArray()[1]).getValue()
那么,你能提出一些建议吗?我应该以某种方式将其投射到 DTO 吗?但是如何处理 JSON 中的键(“Customer.Name”、“Customer.Address”),因为这是一个字段列表。
【问题讨论】:
标签: java sdk cumulocity