Skip to content

Commit

Permalink
Merge branch 'unstable' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jihuayu authored Apr 26, 2024
2 parents f25d59f + ae5784d commit 253873b
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions src/types/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 253873b

Please sign in to comment.