diff --git a/source/RobotAPI/libraries/ArmarXObjects/json_conversions.cpp b/source/RobotAPI/libraries/ArmarXObjects/json_conversions.cpp index 161983900123a6848d2e667258236f2bd95aa33a..6080cfda786c3d6115c6647fe7decd4e5faa6b03 100644 --- a/source/RobotAPI/libraries/ArmarXObjects/json_conversions.cpp +++ b/source/RobotAPI/libraries/ArmarXObjects/json_conversions.cpp @@ -9,7 +9,7 @@ #include "ice_conversions.h" -void armarx::to_json(nlohmann::json& j, const ObjectID& id) +void armarx::to_json(simox::json::json& j, const ObjectID& id) { j["dataset"] = id.dataset(); j["className"] = id.className(); @@ -17,7 +17,7 @@ void armarx::to_json(nlohmann::json& j, const ObjectID& id) j["str"] = id.str(); } -void armarx::from_json(const nlohmann::json& j, ObjectID& id) +void armarx::from_json(const simox::json::json& j, ObjectID& id) { id = { @@ -27,7 +27,7 @@ void armarx::from_json(const nlohmann::json& j, ObjectID& id) }; } -void armarx::objpose::to_json(nlohmann::json& j, const ObjectPose& op) +void armarx::objpose::to_json(simox::json::json& j, const ObjectPose& op) { j["providerName"] = op.providerName; j["objectType"] = ObjectTypeNames.to_name(op.objectType); @@ -52,7 +52,7 @@ void armarx::objpose::to_json(nlohmann::json& j, const ObjectPose& op) } -void armarx::objpose::from_json(const nlohmann::json& j, ObjectPose& op) +void armarx::objpose::from_json(const simox::json::json& j, ObjectPose& op) { op.providerName = j.at("providerName"); op.objectType = ObjectTypeNames.from_name(j.at("objectType")); @@ -77,7 +77,7 @@ void armarx::objpose::from_json(const nlohmann::json& j, ObjectPose& op) } -void armarx::objects::to_json(nlohmann::json& j, const SceneObject& rhs) +void armarx::objects::to_json(simox::json::json& j, const SceneObject& rhs) { j["class"] = rhs.className; j["instanceName"] = rhs.instanceName; @@ -92,7 +92,7 @@ void armarx::objects::to_json(nlohmann::json& j, const SceneObject& rhs) } -void armarx::objects::from_json(const nlohmann::json& j, SceneObject& rhs) +void armarx::objects::from_json(const simox::json::json& j, SceneObject& rhs) { j.at("class").get_to(rhs.className); if (j.count("instanceName")) @@ -128,13 +128,13 @@ void armarx::objects::from_json(const nlohmann::json& j, SceneObject& rhs) -void armarx::objects::to_json(nlohmann::json& j, const Scene& rhs) +void armarx::objects::to_json(simox::json::json& j, const Scene& rhs) { j["objects"] = rhs.objects; } -void armarx::objects::from_json(const nlohmann::json& j, Scene& rhs) +void armarx::objects::from_json(const simox::json::json& j, Scene& rhs) { j.at("objects").get_to(rhs.objects); } diff --git a/source/RobotAPI/libraries/ArmarXObjects/json_conversions.h b/source/RobotAPI/libraries/ArmarXObjects/json_conversions.h index 608ad14424234ef4120f117d511310a42be71bcc..0a5e83b61aa9479d3d67344f585564c2c60d2d75 100644 --- a/source/RobotAPI/libraries/ArmarXObjects/json_conversions.h +++ b/source/RobotAPI/libraries/ArmarXObjects/json_conversions.h @@ -1,28 +1,28 @@ #pragma once -#include <SimoxUtility/json/json.hpp> +#include <SimoxUtility/json/json.h> #include "forward_declarations.h" namespace armarx { - void to_json(nlohmann::json& j, const ObjectID& value); - void from_json(const nlohmann::json& j, ObjectID& value); + void to_json(simox::json::json& j, const ObjectID& value); + void from_json(const simox::json::json& j, ObjectID& value); } namespace armarx::objpose { - void to_json(nlohmann::json& j, const ObjectPose& op); - void from_json(const nlohmann::json& j, ObjectPose& op); + void to_json(simox::json::json& j, const ObjectPose& op); + void from_json(const simox::json::json& j, ObjectPose& op); } namespace armarx::objects { - void to_json(nlohmann::json& j, const SceneObject& rhs); - void from_json(const nlohmann::json& j, SceneObject& rhs); + void to_json(simox::json::json& j, const SceneObject& rhs); + void from_json(const simox::json::json& j, SceneObject& rhs); - void to_json(nlohmann::json& j, const Scene& rhs); - void from_json(const nlohmann::json& j, Scene& rhs); + void to_json(simox::json::json& j, const Scene& rhs); + void from_json(const simox::json::json& j, Scene& rhs); } diff --git a/source/RobotAPI/libraries/armem_objects/server/instance/Segment.cpp b/source/RobotAPI/libraries/armem_objects/server/instance/Segment.cpp index 72faed5fee3f85ff9e34d8e3b821c33598d52f37..0dbe6db72f1b167114b0d211c93c3a37c9202d4a 100644 --- a/source/RobotAPI/libraries/armem_objects/server/instance/Segment.cpp +++ b/source/RobotAPI/libraries/armem_objects/server/instance/Segment.cpp @@ -815,13 +815,13 @@ namespace armarx::armem::server::obj::instance { if (const std::optional<std::filesystem::path> path = resolveSceneFilename(filename)) { - const nlohmann::json j = scene; - ARMARX_INFO << "Storing scene snapshot at: \n" << path.value() << "\n\n" << j.dump(2); + + ARMARX_INFO << "Storing scene snapshot at: \n" << path.value(); try { - nlohmann::write_json(path.value(), j, 2); + simox::json::write(path.value(), scene, 2); } - catch (const std::ios_base::failure& e) + catch (const simox::json::error::JsonError& e) { ARMARX_WARNING << "Storing scene snapshot failed: \n" << e.what(); } @@ -846,20 +846,15 @@ namespace armarx::armem::server::obj::instance std::optional<armarx::objects::Scene> Segment::loadScene(const std::filesystem::path& path) { - ARMARX_INFO << "Loading scene snapshot from: \n" << path; - nlohmann::json j; try { - j = nlohmann::read_json(path); + return simox::json::read<armarx::objects::Scene>(path); } - catch (const std::ios_base::failure& e) + catch (const simox::json::error::JsonError& e) { ARMARX_WARNING << "Loading scene snapshot failed: \n" << e.what(); return std::nullopt; } - - armarx::objects::Scene snapshot = j; - return snapshot; }