0

I have a payload with many fields but i would like to send only the fields that they are not empty to the Backend ,so i tried to use enrich mediator to remove those fields if they are empty but i got an error .

This is my payload factory :

                        <payloadFactory media-type="json">
                            <format>
                                {
  "_putupdateuser": {
                 "BADLOGINS": $1,
                 "EMAIL": "$2",
                 "FRAMED_ROUTE": "$3"
                       }
}
</format>
                            <args>
                                <arg evaluator="xml" expression="get-property('BADLOGINS')"/>
                                <arg evaluator="xml" expression="get-property('EMAIL')"/>
                                <arg evaluator="xml" expression="get-property('FRAMED_ROUTE')"/>
                            </args>
                        </payloadFactory>

This is my implementation of enrich mediator :

                        <enrich>
                            <source clone="false" xpath="json-eval($._putupdateuser.FRAMED_ROUTE)"/>
                            <target action="remove" type="body"/>
                        </enrich>

This is the error i got :

Caused by: com.google.gson.stream.MalformedJsonException: Unexpected value at line 3 column 32 path $._putupdateuser.BADLOGINS
at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1568)
Oussama Nairi
  • 146
  • 1
  • 10

1 Answers1

0

As per the documentation, this feature is only available as a WSO2 update. Hence try a solution like using the Script Mediator as mentioned here.

Another option is to not add the element at all if the values are null. You can have an Enrich mediator within a Filter Mediator and if only the value is not empty you can add the element. Refer the sample 2 here.

ycr
  • 12,828
  • 2
  • 25
  • 45