Add String-based JSON API to avoid unnecessary conversions (#3369) #3394
+458
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds String-based overloads for JSON commands to eliminate unnecessary conversion overhead between String ↔ JsonValue objects, addressing performance concerns raised in the feature request #3369.
Important Note
The existing JSON API assumes users only work with
JsonValue
objects. In certain cases, applications might want to provide a String interface instead, because otherwise they'd have to convert from string toJsonValue
and then the driver would convert back to String and then to a byte array.This approach provides String-based overloads that work directly with String input/output parameters, instead of
JsonValue
objects, eliminating unnecessary conversions while maintaining full backward compatibility.Performance Benefits
String → JsonValue.of() → toString() → getBytes() → ByteBuffer.wrap() → array()
String → getBytes()
(direct conversion)Changes Made
New String Overload Methods Added
jsonArrappend(K key, JsonPath jsonPath, String... jsonStrings)
jsonArrindex(K key, JsonPath jsonPath, String jsonString, JsonRangeArgs range)
jsonArrinsert(K key, JsonPath jsonPath, int index, String... jsonStrings)
jsonMerge(K key, JsonPath jsonPath, String jsonString)
jsonSet(K key, JsonPath jsonPath, String jsonString, JsonSetArgs options)
jsonStrappend(K key, JsonPath jsonPath, String jsonString)
Core Implementation
Testing