【问题标题】:DataWeave best practices when null variable assignment空变量赋值时的 DataWeave 最佳实践
【发布时间】:2015-12-07 06:28:59
【问题描述】:

这是一个 JSON-JSON 转换,将布尔输入 ("true"|"false") 转换为字符输出 ('Y'|'N')。 所以我们选择类似的东西:

varOutput: ('Y' when payload.varInput otherwise 'N')

但是如果 varInput 为空怎么办?我们有例外。我可以用另一个 when-otherwise 来控制它:

varOutput: ('Y' when payload.varInput != null otherwise 'N')
when payload.varInput != null otherwise null,

最后一个是空安全的,但我觉得应该有更优雅的方式。

【问题讨论】:

    标签: json mule integration transformation dataweave


    【解决方案1】:

    使用default

    {varOutput: ( payload.varInput default 'N')
     }
    

    或者除非/否则是 null 安全的并且更优雅一点:

    { 
        varOutput: ('Y' unless payload.varInput !=null otherwise 'N')
    }
    

    【讨论】:

    • 仍然需要将 true 转换为 'Y'。 { varOutput: 'Y' when (payload.varInput default false) default 'N' } 怎么样
    • 当然,看起来不错。添加了另一个选项,除非/否则。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 2020-09-15
    • 1970-01-01
    • 2014-10-22
    相关资源
    最近更新 更多