Pipeline containsKey check fails when top-level object does not exist

Hi everyone!

I'm struggling to find an answer to this issue and i keep receiving the error

Cannot invoke "Object.getClass()" because "value" is null

The problem occurs when I have an object - in this case error - that may or may not exist but I need to check for the existence of a sub-field within that object.

"if" : "ctx.error?.containsKey('code')"

This works when the error object exists but the field code does not exist, but fails when the entire error object is absent, with the above error.

Anyone know how to resolve?

Many thanks in advance.

I found the answer i needed - i'll post here in case anyone else struggles with a similar problem.

The resolution is to check the existence of the top-level object and then the existence of the field within the object in the same conditional if statement. It seems that the logic short-circuits as soon as the condition is false so doesn't go on to check the existence of the field if the object check fails:

"if" : "ctx.containsKey('error') && ctx['error'].containsKey('code')"

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.