Skip to content

Commit

Permalink
Fix json path issue in Mediators
Browse files Browse the repository at this point in the history
Fix issue with Enrich mediator and foreach meadiator after Json Path Upgrade
Fix wso2/product-micro-integrator#3116
  • Loading branch information
dulanjalidilmi committed Feb 15, 2024
1 parent 564af81 commit cb0fde9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public boolean mediate(MessageContext synCtx) {
+ " is not a valid JSON array", synCtx);
}
JsonArray iterableJsonArray = iterableChildElements.getAsJsonArray();
// If the iterableJsonArray is empty, then no need to continue the mediation
if (iterableJsonArray.isEmpty()){
log.info("No elements found for the JSONPath : " + expression);
return true;
}
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Splitting with JSONPath : " + expression + " resulted in " +
iterableJsonArray.size() + " elements.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,15 @@ private String removeJSONFromString(MessageContext synCtx, String inputString, S
if (path.equals("$") || path.equals("$.")) {
result = "";
} else {
DocumentContext doc = JsonPath.parse(result);
doc.delete(path);
result = doc.jsonString();
Object list = JsonPath.compile(path).read(result);
if (!((JsonArray) list).isEmpty()) {
DocumentContext doc = JsonPath.parse(result);
doc.delete(path);
result = doc.jsonString();
} else {
log.warn("No matching elements were found for the given JSONPath: " + path + ". Therefore, " +
"no elements were removed.");
}
}
}
}
Expand Down

0 comments on commit cb0fde9

Please sign in to comment.