MCPcopy Create free account
hub / github.com/MITK/MITK / FromJSON

Method FromJSON

Modules/Core/src/DataManagement/mitkPropertyList.cpp:387–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

385}
386
387void mitk::PropertyList::FromJSON(const nlohmann::json& j)
388{
389 mitk::CoreServicePointer<mitk::IPropertyDeserialization> service(mitk::CoreServices::GetPropertyDeserialization());
390 PropertyMap properties;
391
392 auto jObject = j.get<nlohmann::json::object_t>();
393
394 for (const auto& [type, serializedProperties] : jObject)
395 {
396 auto prototype = service->CreateInstance(type);
397
398 if (prototype.IsNull())
399 {
400 MITK_ERROR << "Cannot create instance(s) of class \"" << type << "\"!";
401 continue;
402 }
403
404 auto serializedPropertiesObject = serializedProperties.get<nlohmann::json::object_t>();
405
406 for (const auto& [name, serializedProperty] : serializedPropertiesObject)
407 {
408 BaseProperty::Pointer property = static_cast<BaseProperty*>(prototype->CreateAnother().GetPointer());
409 property->FromJSON(serializedProperty);
410 properties[name] = property;
411 }
412 }
413
414 m_Properties = properties;
415}
416
417nlohmann::json mitk::ConvertPropertyListToSelfContainedJson(const mitk::PropertyList* propertyList)
418{

Callers 2

ToJSONMethod · 0.45

Calls 4

GetPointerMethod · 0.80
CreateInstanceMethod · 0.45
IsNullMethod · 0.45
CreateAnotherMethod · 0.45

Tested by

no test coverage detected