Skip to content

Commit

Permalink
Merge pull request #4317 from cwisniew/fix-4280-pt2-electric-boogaloo
Browse files Browse the repository at this point in the history
Apply compat fix for json.path.set and json.path.delete as well
  • Loading branch information
cwisniew authored Oct 16, 2023
2 parents 9d007c2 + e725da5 commit b91b29b
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,12 @@ private JsonElement shallowCopy(JsonElement jsonElement) {
* @return The resulting json data.
*/
private JsonElement jsonPathDelete(JsonElement json, String path) {
return JsonPath.using(jaywayConfig).parse(shallowCopy(json)).delete(path).json();
try {
return JsonPath.using(jaywayConfig).parse(shallowCopy(json)).delete(path).json();
} catch (PathNotFoundException ex) {
// Return original json, this is to preserve backwards compatability pre library update
return json;
}
}

/**
Expand Down Expand Up @@ -906,7 +911,12 @@ private JsonElement jsonPathPut(JsonElement json, String path, String key, Objec
private JsonElement jsonPathSet(JsonElement json, String path, Object info) {
Object value = asJsonElement(info);

return JsonPath.using(jaywayConfig).parse(shallowCopy(json)).set(path, value).json();
try {
return JsonPath.using(jaywayConfig).parse(shallowCopy(json)).set(path, value).json();
} catch (PathNotFoundException ex) {
// Return original json, this is to preserve backwards compatability pre library update
return json;
}
}

/**
Expand Down

0 comments on commit b91b29b

Please sign in to comment.