## 运算符在 JSON 个对象上的行为

Behavior of ## operator on JSON objects

该问题与此处提出的解决方案密切相关 ,该解决方案建议使用 ## 运算符来评估 JSON 对象是否为空。 建议的解决方案是使用一些条件替换所以

* def data = { a: 'hello', b: null, c: null }
* def temp = data.c ? { baz: data.c } : null
* def json = { foo: '#(data.a)', bar: '#(data.b)', jsonObject: '##(temp)' }
* match json == { foo: 'hello', bar: null }

如果 data.c 等于 null,此解决方案将完美运行,但如果 data.c 设置为某个值,例如

,则它会出现问题
 * def data = { a: 'hello', b: null, c: 'world' }
 * def temp = data.c ? { baz: data.c } : null
 * def json = { foo: '#(data.a)', bar: '#(data.b)', jsonObject: '##(temp)' }
 * match json == { foo: 'hello', bar: null, jsonObject:{baz:'world'}}

失败是因为

 actual: '##(temp)', expected: {baz=world}.

换句话说,## 运算符似乎无法正确识别临时变量中的 json 对象。请注意,如果 temp 变量的计算结果为 null,则解决方案可以完美运行。我做错了什么吗?如果没有,是否有一些解决方法?

你能试试 Karate 1.1.0.RC5 因为我认为这在那个版本中已经修复了。