MCPcopy Create free account
hub / github.com/Illation/ETEngine / FromJsonValue

Function FromJsonValue

Engine/source/EtCore/Reflection/serialization.cpp:746–838  ·  view source on GitHub ↗

--------------------------------- FromJsonValue Extract a JSON Value into a variant using its value type

Source from the content-addressed store, hash-verified

744// Extract a JSON Value into a variant using its value type
745//
746void FromJsonValue(JSON::Value const* jVal, rttr::type &valueType, rttr::variant &var)
747{
748 rttr::type localType = valueType;
749 if (!ExtractPointerValueType(localType, jVal))
750 {
751 return;
752 }
753
754 switch (jVal->GetType())
755 {
756 case JSON::JSON_Array:
757 {
758 if (localType.is_sequential_container())
759 {
760 auto view = var.create_sequential_view();
761
762 if (!ArrayFromJsonRecursive(view, jVal))
763 {
764 LOG("FromJsonValue > There was an issue deserializing the sequential view, typeName: '"
765 + localType.get_name().to_string() + std::string("'!"), LogLevel::Warning);
766 }
767 }
768 else if (localType.is_associative_container())
769 {
770 auto associativeView = var.create_associative_view();
771
772 if (!AssociativeViewFromJsonRecursive(associativeView, jVal))
773 {
774 LOG("FromJsonValue > There was an issue deserializing the associate view, typeName: '"
775 + localType.get_name().to_string() + std::string("'!"), LogLevel::Warning);
776 }
777 }
778 else
779 {
780 LOG("FromJsonValue > Found a JSON value of type array, but the property is not a sequential or associate container, typeName: '"
781 + localType.get_name().to_string() + std::string("'!"), LogLevel::Warning);
782 }
783
784 break;
785 }
786
787 case JSON::JSON_Object:
788 {
789 // for pointers we will have to create the type
790 if (localType != valueType)
791 {
792 // find the right constructor for our type
793 rttr::constructor ctor = localType.get_constructor();
794
795 //use it
796 if (ctor.is_valid())
797 {
798 var = ctor.invoke();
799 }
800 else
801 {
802 LOG(FS("FromJsonValue > Failed to get a valid constructor from property, typeName: '%s'!", localType.get_name().data()),
803 LogLevel::Warning);

Callers 1

ObjectFromJsonRecursiveFunction · 0.85

Calls 6

ExtractPointerValueTypeFunction · 0.85
ArrayFromJsonRecursiveFunction · 0.85
ObjectFromJsonRecursiveFunction · 0.85
ExtractBasicTypesFunction · 0.85
GetTypeMethod · 0.45

Tested by

no test coverage detected