Expression
组件的JSON:
{
"FooObjects":
[
{
"FooPropertyOne": "value for property one"
, "FooPropertyTwo": "value for property two"
, "FooPropertyThree": "value for property three"
, "FooId": 22031
, "FooBarRelationships":
[
{
"FooBarRelationshipId": 18014
, "RelationshipProperty": "value for rel property"
, "Bar": { "BarPropertyOne": "value for property one", "BarId": 11379 }
}
, {
"FooBarRelationshipId": 18015
, "RelationshipProperty": "value for rel property"
, "Bar": { "BarPropertyOne": "value for property one", "BarId": 10001 }
}
]
}
]
}
这是我想要的结果:
{
"FooObjects":
[
{
"FooPropertyOne": "value for property one"
, "FooPropertyTwo": "value for property two"
, "FooPropertyThree": "value for property three"
, "FooId": 22031
, "FooUrl": "https://server/path/to/foo?FooId=22013"
, "Bars":
[
{ "BarPropertyOne": "value for property one", "BarId": 11379 }
, { "BarPropertyOne": "value for property one", "BarId": 10001 }
]
}
]
}
这是表达式组件:
<expression-component doc:name="Expression"><![CDATA[payload =
[
"FooObjects": ([
"FooPropertyOne": $.FooPropertyOne
, "FooPropertyTwo": $.FooPropertyTwo
, "FooPropertyThree": $.FooPropertyThree
, "FooId": $.FooId
, "FooURl": "https://server/path/to/foo?FooId=" + $.FooId
, "Bars": $.FooBarRelationships
] in payload.FooObjects)
];]]></expression-component>
我一直在猜测代替$.FooBarRelationships
的语法。我能想到的最好的是(['BarPropertyOne':$.Bar.BarPropertyOne]in $.FooBarRelationships)
。这让我:
[Error: could not access: Bar; in class: java.util.LinkedHashMap]
[Near : {... $.Bar.BarPropertyOne....}]
^
我该如何进行这种转变?如果我遗漏关于Bars
的部分,除了没有得到我需要的所有数据之外,一切正常。谢谢!
编辑:我更改了示例以更清晰地显示多重性。
答案 0 :(得分:1)
我能够完成这项工作的唯一方法是通过一个功能:
<configuration>
<expression-language>
<global-functions>
def makeBars(fooBarRelationships) {
(['BarPropertyOne':$.Bar.BarPropertyOne] in fooBarRelationships)
}
</global-functions>
</expression-language>
</configuration>
然后在流程中我可以使用:
<expression-component doc:name="Expression"><![CDATA[payload =
[
"FooObjects": ([
"FooPropertyOne": $.FooPropertyOne
, "FooPropertyTwo": $.FooPropertyTwo
, "FooPropertyThree": $.FooPropertyThree
, "FooId": $.FooId
, "FooURl": "https://server/path/to/foo?FooId=" + $.FooId
, "Bars": makeBars($.FooBarRelationships)
] in payload.FooObjects)
];]]></expression-component>