You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
925 B

  1. #pragma once
  2. #include <nlohmann/json.hpp>
  3. #include <string>
  4. namespace nlohmann
  5. {
  6. class JsonPatchFormatException : public std::exception
  7. {
  8. public:
  9. explicit JsonPatchFormatException( std::string msg ) : ex_{ std::move( msg ) } {}
  10. inline const char* what() const noexcept override final { return ex_.c_str(); }
  11. private:
  12. std::string ex_;
  13. };
  14. class json_patch
  15. {
  16. public:
  17. json_patch() = default;
  18. json_patch( json&& patch );
  19. json_patch( const json& patch );
  20. json_patch& add( const json::json_pointer&, json value );
  21. json_patch& replace( const json::json_pointer&, json value );
  22. json_patch& remove( const json::json_pointer& );
  23. json& get_json() { return j_; }
  24. const json& get_json() const { return j_; }
  25. operator json() const { return j_; }
  26. private:
  27. json j_ = nlohmann::json::array();
  28. static void validateJsonPatch( json const& patch );
  29. };
  30. } // namespace nlohmann