如何检查 mule 4 中接收到的 JSON 是否为空/null
how to check whether the JSON recieved is empty/ nulll in mule 4
我正在尝试检查 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=
请提出解决方案。
应按照此处所述正确检查所有输入
https://simpleflatservice.com/mule4/DoubleAndTripleCheckTheInput.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
如果有效负载的 MIME 类型是 application/json,则空对象是无效的 JSON,无法解析。负载需要 {}
。参见Mule doc。如果 MIME 类型是 application/json.
,客户端的解决方案是发送 {}
我正在尝试检查 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=
请提出解决方案。
应按照此处所述正确检查所有输入 https://simpleflatservice.com/mule4/DoubleAndTripleCheckTheInput.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
如果有效负载的 MIME 类型是 application/json,则空对象是无效的 JSON,无法解析。负载需要 {}
。参见Mule doc。如果 MIME 类型是 application/json.
{}