Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix json path issue in mediators #2142

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we add an info log saying the filter gave an empty result, so we are not performing the delete.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

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
Loading