简体   繁体   中英

How to remove JSON field from payload factory using WSO2 EI Enrich Mediator?

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)

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM