fix for empty expression primitive type serialization

Signed-off-by: chcurran <82187351+carlitosan@users.noreply.github.com>
monroegm-disable-blank-issue-2
chcurran 4 years ago
parent 2dd00e2983
commit b7c478b85e

@ -28,6 +28,19 @@ namespace AZ
private: private:
using VariableDescriptor = ExpressionEvaluation::ExpressionTree::VariableDescriptor; using VariableDescriptor = ExpressionEvaluation::ExpressionTree::VariableDescriptor;
static constexpr AZStd::string_view EmptyAnyIdentifier = "Empty AZStd::any";
static bool IsEmptyAny(const rapidjson::Value& typeId)
{
if (typeId.IsString())
{
AZStd::string_view typeName(typeId.GetString(), typeId.GetStringLength());
return typeName == EmptyAnyIdentifier;
}
return false;
}
JsonSerializationResult::Result Load JsonSerializationResult::Result Load
( void* outputValue ( void* outputValue
, [[maybe_unused]] const Uuid& outputValueTypeId , [[maybe_unused]] const Uuid& outputValueTypeId
@ -62,22 +75,25 @@ namespace AZ
, JsonSerialization::TypeIdFieldIdentifier)); , JsonSerialization::TypeIdFieldIdentifier));
} }
result.Combine(LoadTypeId(typeId, typeIdMember->value, context)); if (!IsEmptyAny(typeIdMember->value))
if (typeId.IsNull())
{
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Catastrophic
, "ExpressionTreeVariableDescriptorSerializer::Load failed to load the AZ TypeId of the value");
}
AZStd::any storage = context.GetSerializeContext()->CreateAny(typeId);
if (storage.empty() || storage.type() != typeId)
{ {
return context.Report(result, "ExpressionTreeVariableDescriptorSerializer::Load failed to load a value matched the " result.Combine(LoadTypeId(typeId, typeIdMember->value, context));
"reported AZ TypeId. The C++ declaration may have been deleted or changed."); if (typeId.IsNull())
{
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Catastrophic
, "ExpressionTreeVariableDescriptorSerializer::Load failed to load the AZ TypeId of the value");
}
AZStd::any storage = context.GetSerializeContext()->CreateAny(typeId);
if (storage.empty() || storage.type() != typeId)
{
return context.Report(result, "ExpressionTreeVariableDescriptorSerializer::Load failed to load a value matched the "
"reported AZ TypeId. The C++ declaration may have been deleted or changed.");
}
result.Combine(ContinueLoadingFromJsonObjectField(AZStd::any_cast<void>(&storage), typeId, inputValue, "Value", context));
outputDatum->m_value = storage;
} }
result.Combine(ContinueLoadingFromJsonObjectField(AZStd::any_cast<void>(&storage), typeId, inputValue, "Value", context));
outputDatum->m_value = storage;
// any storage end // any storage end
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
@ -123,20 +139,32 @@ namespace AZ
, azrtti_typeid<decltype(inputScriptDataPtr->m_supportedTypes)>() , azrtti_typeid<decltype(inputScriptDataPtr->m_supportedTypes)>()
, context)); , context));
rapidjson::Value typeValue; if (!inputScriptDataPtr->m_value.empty())
result.Combine(StoreTypeId(typeValue, inputScriptDataPtr->m_value.type(), context)); {
outputValue.AddMember rapidjson::Value typeValue;
( rapidjson::StringRef(JsonSerialization::TypeIdFieldIdentifier) result.Combine(StoreTypeId(typeValue, inputScriptDataPtr->m_value.type(), context));
, AZStd::move(typeValue) outputValue.AddMember
, context.GetJsonAllocator()); ( rapidjson::StringRef(JsonSerialization::TypeIdFieldIdentifier)
, AZStd::move(typeValue)
result.Combine(ContinueStoringToJsonObjectField , context.GetJsonAllocator());
( outputValue
, "Value" result.Combine(ContinueStoringToJsonObjectField
, AZStd::any_cast<void>(const_cast<AZStd::any*>(&inputScriptDataPtr->m_value)) ( outputValue
, defaultScriptDataPtr ? AZStd::any_cast<void>(const_cast<AZStd::any*>(&defaultScriptDataPtr->m_value)) : nullptr , "Value"
, inputScriptDataPtr->m_value.type() , AZStd::any_cast<void>(const_cast<AZStd::any*>(&inputScriptDataPtr->m_value))
, context)); , defaultScriptDataPtr ? AZStd::any_cast<void>(const_cast<AZStd::any*>(&defaultScriptDataPtr->m_value)) : nullptr
, inputScriptDataPtr->m_value.type()
, context));
}
else
{
rapidjson::Value emptyAny;
emptyAny.SetString(EmptyAnyIdentifier.data(), aznumeric_caster(EmptyAnyIdentifier.size()), context.GetJsonAllocator());
outputValue.AddMember
( rapidjson::StringRef(JsonSerialization::TypeIdFieldIdentifier)
, AZStd::move(emptyAny)
, context.GetJsonAllocator());
}
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
? "VariableDescriptor Store finished saving VariableDescriptor" ? "VariableDescriptor Store finished saving VariableDescriptor"

Loading…
Cancel
Save