Repository navigation
Conversation
…ys in update Treat bracketed metadata and context keys as literal keys in update.
There was a problem hiding this comment.
Code Review
This pull request introduces a parseArrays parameter to the JSON utility methods in JsonUtils to control whether bracketed keys (e.g., x[2]) are parsed as arrays or treated as literal keys. This parameter is set to false when updating contexts and metadata fields in StorageImpl.java to prevent incorrect array parsing. The reviewer suggested a performance optimization in JsonUtils.treeify to check the parseArrays flag before instantiating and running the regex matcher, which avoids unnecessary overhead when array parsing is disabled.
| Matcher matcher = array_part.matcher(split); | ||
| if (matcher.matches()) { | ||
| if (parseArrays && matcher.matches()) { | ||
| name = matcher.group(1); | ||
| String idxString = matcher.group(2); | ||
| idx = Integer.parseInt(idxString); |
There was a problem hiding this comment.
When parseArrays is false, creating a Matcher and running the regex match is unnecessary. Checking parseArrays first avoids this overhead.
if (parseArrays) {
Matcher matcher = array_part.matcher(split);
if (matcher.matches()) {
name = matcher.group(1);
String idxString = matcher.group(2);
idx = Integer.parseInt(idxString);
}
}
Treat bracketed metadata and context keys as literal keys in update.