Skip to content

Commit

Permalink
Merge pull request #2142 from dulanjalidilmi/master
Browse files Browse the repository at this point in the history
Fix json path issue in mediators
  • Loading branch information
dulanjalidilmi authored Feb 16, 2024
2 parents e217b50 + 8294911 commit 3cdded7
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.info("No matching elements were found for the given JSONPath: " + path + ". Therefore, " +
"no elements were removed.");
}
}
}
}
Expand Down

0 comments on commit 3cdded7

Please sign in to comment.