【问题标题】:Mulesoft displaying null values for nested properties in an array (even though it displays those values when i refer to the outer property.)Mulesoft 为数组中的嵌套属性显示空值(即使它在我引用外部属性时显示这些值。)
【发布时间】:2021-05-16 02:13:35
【问题描述】:

我在读取嵌套属性值时遇到问题。 我已将入站消息转换为以下结构 - 但是,当我将内部属性读取为 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

    })
    })

这是输出: 它在引用外部属性时显示。但是当我引用内部属性时,它会将它们显示为 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
      }
    ]
  }
  

我浪费的最终结果是,对于每个调用,我都有一串“产品-产品消息,产品-产品消息”,但即使你只是帮助我访问和提取子值,它也会很棒。

【问题讨论】:

  • 我在尝试输入和脚本时遇到错误。例如,有效负载中没有值成员。请先检查并修复错误。

标签: mule dataweave mulesoft


【解决方案1】:

您可以使用此数据编织来提取子值。最好使用 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
    }
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 2014-03-22
    • 2020-12-01
    • 1970-01-01
    • 2017-09-13
    • 1970-01-01
    相关资源
    最近更新 更多