12 catch (
const nlohmann::detail::out_of_range&)
16 catch (
const nlohmann::detail::type_error&)
22 void json::setTypeName(nlohmann::json& j,
const std::string& key,
const std::string& typeName)
76 _from_json(j, element);
81 _to_json(j, *shapePtr);
86 _from_json_ptr(j, shapePtr);
89 ElementJsonSerializers::ElementJsonSerializer& ElementJsonSerializers::getSerializer(
const nlohmann::json& j)
94 ElementJsonSerializers::ElementJsonSerializer& ElementJsonSerializers::getSerializer(
const std::string& demangledTypeName)
96 return _instance._getSerializer(demangledTypeName);
101 return _instance._getRegisteredTypes();
106 return _instance._isTypeRegistered(typeName);
111 return getSerializer(simox::meta::get_type_name(element)).to_json(j, element);
117 if (typeName != simox::meta::get_type_name(element))
121 getSerializer(typeName).from_json(j, element);
135 getSerializer(j).from_json(j, shapePtr);
143 ElementJsonSerializers::ElementJsonSerializers()
149 ElementJsonSerializers::ElementJsonSerializer& ElementJsonSerializers::_getSerializer(
150 const std::string& demangledTypeName)
152 if (
auto find = _serializers.find(demangledTypeName); find != _serializers.end())
158 throw error::NoSerializerForType(demangledTypeName);
162 std::vector<std::string> ElementJsonSerializers::_getRegisteredTypes()
const
164 std::vector<std::string> types;
165 for (
const auto& [typeName, serializer] : _serializers)
167 types.push_back(typeName);
172 bool ElementJsonSerializers::_isTypeRegistered(
const std::string& typeName)
const
174 return _serializers.count(typeName) > 0;