Monday, February 13, 2017

XPath: check if property is null

Suppose you are receiving an object with a testProperty property in input...
For example:
case 1)
{
 "testProperty":null
}
or
case 2)
{
 "testProperty":"test"
}

Please declare the property in this way:
<property xmlns:cct="http://www.tempuri.org/" name="custom_property_name" expression="//testProperty/text()" scope="default" type="STRING"/>

and test it in this way:
<log level="custom">
    <property expression="boolean(get-property('custom_property_name'))" name="message"/>

</log>

The output will be:
case 1)
INFO - LogMediator message= false
case 2)
INFO - LogMediator message= true


Bye...