首页 > 解决方案 > 在 mule 3 中进行映射时从数组对象中删除空 json 数组

问题描述

如何在进行转换时应用过滤器来删除空数组。我试图应用 sizeOf ($) != 0 但这不起作用。我可以通过创建函数来做到这一点,但在这里我必须在执行 map.kindly 建议解决方案时删除。

            %dw 1.0
            %output application/json
            ---
            {
            employees: {
                employee:  (flowVars.varInputData.request.application.applicants) map ((applicant , indexOfApplicant) -> {
                        (flowVars.varMbResponse.application.applicants filter ($.customerID == applicant.customerID) map {
                        "source": "EMI_IMP",
                        "loanData": ($.customBureauResponse.customResponse.accountList map {
                                    "customerGender": applicant.gender
                })
                })

                })  
            }
            }

来自 dwl 的回应:

            {
            "EMIComputations": {
                "eMIComputation": [{
                        "source": "EMI_IMP",
                        "loanData": [{
                                "customerGender": "F",
                            },
                            {
                                "customerGender": "M",
                            }
                        ]
                    },
                    {

                    },
                    {

                    }
                ]
            }
            }

预期输出:

            "EMIComputations": {
                "eMIComputation": [{
                        "source": "EMI_IMP",
                        "loanData": [{
                                "customerGender": "M",
                            },
                            {
                                "customerGender": "M",
                            }
                        ]
                    }
                ]
            }
            }

标签: muledataweavemulesoftmule-esb

解决方案


推荐阅读