mule - Mulesoft 为数组中的嵌套属性显示空值(即使它在我引用外部属性时显示这些值。)
问题描述
我在读取嵌套属性值时遇到问题。我已将入站消息转换为以下结构 - 但是,当我将内部属性读取为 map 时,它会将它们显示为 null .. 但是如果我直接将父级拉到引用中,我可以看到内部值。入站有效载荷:
[
{
"Name": "C-name1",
"child": [
{
"ProductMessage__r": {
"ProductMessageText__c": "testvalues",
"Id": null,
"type": "ProductMessage__c"
},
"Id": null,
"type": "CallMessage__c",
"Product__r": {
"Id": null,
"type": "Product__c",
"Name": "stackov"
}
},
{
"ProductMessage__r": {
"ProductMessageText__c": "stack overflow",
"Id": null,
"type": "ProductMessage__c"
},
"Id": null,
"type": "CallMessage__c",
"Product__r": {
"Id": null,
"type": "Product__c",
"Name": "stackover"
}
}
]
},
{
"callName": "C-02436592",
"child": [
{
"ProductMessage__r": {
"ProductMessageText__c": "stackover flow",
"Id": null,
"type": "ProductMessage__c"
},
"Id": null,
"type": "CallMessage__c",
"Product__r": {
"Id": null,
"type": "Product__c",
"Name": "cooler"
}
},
{
"ProductMessage__r": {
"ProductMessageText__c": "vxcvxcvxc",
"Id": null,
"type": "ProductMessage__c"
},
"Id": null,
"type": "CallMessage__c",
"Product__r": {
"Id": null,
"type": "Product__c",
"Name": "Mixtard® 30 IND"
}
}
]
}
]
现在在上面的有效负载中,如果我引用父值**(二、三)**,它会正确显示所有值,但如果我访问子参数(一、四、五和六):
%dw 2.0
output application/json
var t = payload.values
---
t map((item,index)->{
callname:t[index].callName,
childprod2: t[index].child map({
one: $. product__r.Name, //diplsys null
two : $,//displays the entire nested values
three: t[index].child,
four : $. product__r, // displays null
five: $. productmessage__r, //null
six: $. productmessage__r. ProductMessageText__c //null
})
})
这是输出:它在引用外部属性时显示。但是当我引用内部属性时,它会将它们显示为空:
[
{
"callname": "C-02436590",
"childprod2": [
{
"one": null,
"two": {
" ProductMessage__r": {
" ProductMessageText__c": "stack overflowtestmix",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
},
"three": [
{
" ProductMessage__r": {
" ProductMessageText__c": "stack overflowtestmix",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
},
{
" ProductMessage__r": {
" ProductMessageText__c": "stack overflowtest",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
},
{
" ProductMessage__r": {
" ProductMessageText__c": "stack overflow stack overflowtest",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
}
],
"four": null,
"five": null,
"six": null
},
{
"one": null,
"two": {
" ProductMessage__r": {
" ProductMessageText__c": "stack overflowtest",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
},
"three": [
{
" ProductMessage__r": {
" ProductMessageText__c": "stack overflowtestmix",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
},
{
" ProductMessage__r": {
" ProductMessageText__c": "stack overflowtest",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
},
{
" ProductMessage__r": {
" ProductMessageText__c": "stack overflow stack overflowtest",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
}
],
"four": null,
"five": null,
"six": null
}
]
},
{
"callname": "C-02436592",
"childprod2": [
{
"one": null,
"two": {
" ProductMessage__r": {
" ProductMessageText__c": "stack overflowtestmix",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
},
"three": [
{
" ProductMessage__r": {
" ProductMessageText__c": "stack overflowtestmix",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
},
{
" ProductMessage__r": {
" ProductMessageText__c": "stack overflowtest",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
},
{
" ProductMessage__r": {
" ProductMessageText__c": "stack overflow stack overflowtest",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
}
],
"four": null,
"five": null,
"six": null
},
{
"one": null,
"two": {
" ProductMessage__r": {
" ProductMessageText__c": "stack overflowtest",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
},
"three": [
{
" ProductMessage__r": {
" ProductMessageText__c": "stack overflowtestmix",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
},
{
" ProductMessage__r": {
" ProductMessageText__c": "stack overflowtest",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
},
{
" ProductMessage__r": {
" ProductMessageText__c": "stack overflow stack overflowtest",
"Id": null,
"type": " ProductMessage__c"
},
"Id": null,
"type": " CallMessage__c",
" Product__r": {
"Id": null,
"type": " Product__c",
"Name": " stack overflow 30 IND"
}
}
],
"four": null,
"five": null,
"six": null
}
]
}
我浪费的最终结果是,对于每个电话,我都有一串“product-productmessage,product-productmessage”,但即使你只是帮助我访问和提取子值,它也会很棒。
解决方案
您可以使用此数据编织来提取子值。最好使用 item.callName 而不是 t[index].callName(虽然两者都是等价的)。map 函数本身迭代数组中的每个项目。
%dw 2.0
output json
var t= payload
---
t map(item,index) ->{
callname:item.callName,
childproduct2:item.child map {
one: $.Product__r.Name,
two:$,
three:$,
four: $.Product__r,
five:$.ProductMessage__r,
six:$.ProductMessage__r.ProductMessageText__c
}
}
推荐阅读
- sql-server - SQL Server 2017 中的情况
- c++ - 脆弱的基类问题会出现在 C++ 中吗?
- intellij-idea - intellij idea 结帐错误:doenst 显示“svn 结帐选项”对话框?
- kotlin - Kotlin 的 fold 是什么让我可以将操作函数放在右括号之后?
- google-cloud-platform - 谷歌云实例显示 SSH 而不是 RDP(Windows 而不是 Linux)
- javascript - 更新到 Codeigniter 3.x 后,为什么在 ajax 调用期间出现 json 解析错误?
- ruby-on-rails - 显示多行错误消息
- mysql - 从 db 表中获取行
- reactjs - 我可以在不违反 React 设计原则的情况下在 reducer 中验证令牌吗?
- java - 为什么java支持255维数组,而在现实生活中我们很少超过2D?