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 836d2f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,16 @@ public boolean mediate(MessageContext synCtx) {
if (((SynapseJsonPath) expression).isWholeBody()){
jsonPayloadElement = modifiedPayloadArray;
} else {
jsonPayloadElement = parsedJsonPayload.set(((SynapseJsonPath) expression).getJsonPath(),
modifiedPayloadArray).json();
Object list = ((SynapseJsonPath) expression).getJsonPath().read(jsonPayload);
if (!((JsonArray) list).isEmpty()) {
jsonPayloadElement = parsedJsonPayload.set(((SynapseJsonPath) expression).getJsonPath(),
modifiedPayloadArray).json();
} else {
String jsonpathEp = ((SynapseJsonPath) expression).getJsonPathExpression();
log.warn("No matching elements were found for the given JSONPath: " + jsonpathEp + ". Therefore, " +
"no elements were modified.");
jsonPayloadElement = parsedJsonPayload.json();
}
}
try {
JsonUtil.getNewJsonPayload(((Axis2MessageContext) synCtx).getAxis2MessageContext(),
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 836d2f0

Please sign in to comment.