My code looks like this:
<property name="BIRTH_DAY" value="18" scope="default" type="STRING"/>
<property expression="$body/jsonObject/data[attribute_id=$ctx:BIRTH_DAY]/attribute_value" name="BirthDay" scope="default" type="STRING"/>
<log>
<property expression="$body/jsonObject/data[attribute_id=$ctx:BIRTH_DAY]/attribute_value" name="Birth Day1"/> <property expression="$ctx:BirthDay" name="Birth Day2"/>
</log>
For some reason, I can only print the Birth day value when I declare the expression directly in the log; i.e. Birth Day1 prints properly, but not Birth Day2
If I define the expression in a payload factory mediator it gets saved.
I believe there is nothing wrong with the expression you were trying. What I think happened is, the WSO2 Payload goes through a process called message building (Converting the binary message to a processable format) if you are trying to work with the payload. This decision is made conditionally by looking at the type of mediators you are using to make the execution efficient, so simply there are 3 types of Mediators.
I assume you just have the properties and the log in your sequence. With that assumption, the Property Mediator
is a Conditionally Content-Aware mediator, so in your case, the runtime didn't think you were trying to do something with the Payload, hence it never built the message to a processable format. So inorder to get around this issue add one of the following at the beginning of the Sequence.
<syn:builder xmlns:syn="http://ws.apache.org/ns/synapse"/>
or
<log level="full"/>
Further Readings.