简体   繁体   English

如何使用 WSO2 EI Enrich Mediator 从有效负载工厂中删除 JSON 字段?

[英]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.我有一个包含许多字段的有效负载,但我只想将它们不为空的字段发送到后端,所以我尝试使用 enrich mediator 删除这些字段(如果它们为空)但我收到错误。

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 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.根据文档,此功能仅作为 WSO2 更新提供。 Hence try a solution like using the Script Mediator as mentioned here .因此,请尝试使用此处提到的 Script Mediator 等解决方案。

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.如果值为 null,另一种选择是根本不添加该元素。您可以在Filter Mediator中有一个Enrich mediator ,如果只有值不为空,您就可以添加该元素。 Refer the sample 2 here .请参阅此处的示例 2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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