Search code examples
muledataweavemulesoftmule4mule-esb

what is the meaning of this in Mule 3 #[payload.?status == 'completed']


In mule 4 the below statement can be used to check weather element is present or not. it returns true or false

payload.key?

can some one please explain what is the meaning of using question mark in the below statement mule 3.

#[payload.?status == 'completed']

how can we achive same in mule 4


Solution

  • It is a "Null Safe" way of fetching values from a payload. You can refer the official document here: https://docs.mulesoft.com/mule-runtime/3.9/mel-cheat-sheet#chained-elements

    In this example, if a field named address is null, the expression throws a NullPointerException.

    #[payload.address.zipcode]
    

    To make this same expression null safe, use the .? operator.

    #[payload.address.?zipcode] 
    

    Using this operator avoids a NullPointerException if address is an empty value, instead it returns null.

    In Mule 4 this is changed, and it is always null safe when extracting data. i.e. payload.address.zipcode will return null if address or payload null