From dce4402d583c53a05dcac6208e4e5217365e954d Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Tue, 15 Feb 2022 09:43:03 +0100 Subject: [PATCH] Use simox json api --- .../ArmarXObjects/json_conversions.cpp | 16 ++++++++-------- .../libraries/ArmarXObjects/json_conversions.h | 18 +++++++++--------- .../armem_objects/server/instance/Segment.cpp | 17 ++++++----------- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/source/RobotAPI/libraries/ArmarXObjects/json_conversions.cpp b/source/RobotAPI/libraries/ArmarXObjects/json_conversions.cpp index 161983900..6080cfda7 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 608ad1442..0a5e83b61 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 72faed5fe..0dbe6db72 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; } -- GitLab