在Mule 4中,如何检查接收到的JSON是否为空的nulll?

问题描述 投票:1回答:1

我试图检查json对象是否为空,但我得到了以下错误。

org.mule.runtime.core.api.expression.ExpressionRuntimeException: "Unable to parse empty input, while reading `obj` as Json.

1|
   ^
Trace:
  at main (line: 1, column: 1)" evaluating expression: "isEmpty(vars.obj)".

此外,我观察到变量在mule调试器中看起来像这样。

obj= 

请提供一个解决方案。

mule dataweave anypoint-studio mule4
1个回答
1
投票

所有的输入都应该像这里描述的那样被正确检查 https:/simpleflatservice.commule4DoubleAndTripleCheckTheInput.html。

null可以提前检查,比如

vars.obj == null or isEmpty(vars.obj)

isEmpty函数在处理空值时完全可以正常工作。

%dw 2.0
output application/json
---
{
    reallyEmpty: isEmpty(''),
    nullOrReallyEmpty: isEmpty(null),
    unknownVaraiable: isEmpty(vars.xyz)
}

输出

{
  "reallyEmpty": true,
  "nullOrReallyEmpty": true,
  "unknownVaraiable": true
}

同时注意WhiteSpaceString

enter image description here

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.