This is an automated email from the ASF dual-hosted git repository.

twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new ae5784db Use jsonpath::replace instead of jsonpointer::replace (#2271)
ae5784db is described below

commit ae5784dbe83bce07f0e5534f84404e7e075daaa4
Author: Twice <[email protected]>
AuthorDate: Thu Apr 25 23:01:29 2024 +0900

    Use jsonpath::replace instead of jsonpointer::replace (#2271)
---
 src/types/json.h | 27 ++-------------------------
 1 file changed, 2 insertions(+), 25 deletions(-)

diff --git a/src/types/json.h b/src/types/json.h
index 5caf212e..2f5c0c45 100644
--- a/src/types/json.h
+++ b/src/types/json.h
@@ -31,8 +31,6 @@
 #include <jsoncons_ext/jsonpath/flatten.hpp>
 #include <jsoncons_ext/jsonpath/json_query.hpp>
 #include <jsoncons_ext/jsonpath/jsonpath_error.hpp>
-#include <jsoncons_ext/jsonpointer/jsonpointer.hpp>
-#include <jsoncons_ext/jsonpointer/jsonpointer_error.hpp>
 #include <jsoncons_ext/mergepatch/mergepatch.hpp>
 #include <limits>
 #include <string>
@@ -163,22 +161,11 @@ struct JsonValue {
         // and in this workaround we can only accept normalized path
         // refer to https://github.com/danielaparker/jsoncons/issues/496
         jsoncons::jsonpath::json_location location = 
jsoncons::jsonpath::json_location::parse(path);
-        jsoncons::jsonpointer::json_pointer ptr{};
 
-        for (const auto &element : location) {
-          if (element.has_name())
-            ptr /= element.name();
-          else {
-            ptr /= element.index();
-          }
-        }
-
-        jsoncons::jsonpointer::replace(value, ptr, new_value.value, true);
+        jsoncons::jsonpath::replace(value, location, new_value.value, true);
       }
     } catch (const jsoncons::jsonpath::jsonpath_error &e) {
       return {Status::NotOK, e.what()};
-    } catch (const jsoncons::jsonpointer::jsonpointer_error &e) {
-      return {Status::NotOK, e.what()};
     }
 
     return Status::OK();
@@ -440,16 +427,8 @@ struct JsonValue {
         // and in this workaround we can only accept normalized path
         // refer to https://github.com/danielaparker/jsoncons/issues/496
         jsoncons::jsonpath::json_location location = 
jsoncons::jsonpath::json_location::parse(path);
-        jsoncons::jsonpointer::json_pointer ptr{};
 
-        for (const auto &element : location) {
-          if (element.has_name())
-            ptr /= element.name();
-          else {
-            ptr /= element.index();
-          }
-        }
-        jsoncons::jsonpointer::replace(value, ptr, patch_value, true);
+        jsoncons::jsonpath::replace(value, location, patch_value, true);
 
         is_updated = true;
       } else if (path == json_root_path) {
@@ -468,8 +447,6 @@ struct JsonValue {
         jsoncons::jsonpath::remove(value, path);
         is_updated = true;
       }
-    } catch (const jsoncons::jsonpointer::jsonpointer_error &e) {
-      return {Status::NotOK, e.what()};
     } catch (const jsoncons::jsonpath::jsonpath_error &e) {
       return {Status::NotOK, e.what()};
     } catch (const jsoncons::ser_error &e) {

Reply via email to