Added backward-compatible support for the old "id" key in material type files, which is being renamed to "name".
This required the use of custom serializers, because the JSON serialization system does not have any means of supporting field name aliases through SerializeContext. Testing: RPI unit test pass and AtomSampleViewer material screenshot test script passes. Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
#include <Atom/RPI.Edit/Common/JsonFileLoadContext.h>
|
||||
#include <Atom/RPI.Edit/Common/JsonUtils.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzCore/Serialization/Json/BaseJsonSerializer.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerializationResult.h>
|
||||
|
||||
#include <AzCore/std/string/string.h>
|
||||
|
||||
@@ -99,6 +101,29 @@ namespace AZ
|
||||
return AZ::Success(AZStd::move(materialType));
|
||||
}
|
||||
}
|
||||
|
||||
void CheckForUnrecognizedJsonFields(const AZStd::string_view* acceptedFieldNames, uint32_t acceptedFieldNameCount, const rapidjson::Value& object, JsonDeserializerContext& context, JsonSerializationResult::ResultCode &result)
|
||||
{
|
||||
for (auto iter = object.MemberBegin(); iter != object.MemberEnd(); ++iter)
|
||||
{
|
||||
bool matched = false;
|
||||
|
||||
for (uint32_t i = 0; i < acceptedFieldNameCount; ++i)
|
||||
{
|
||||
if (iter->name.GetString() == acceptedFieldNames[i])
|
||||
{
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matched)
|
||||
{
|
||||
ScopedContextPath subPath{context, iter->name.GetString()};
|
||||
result.Combine(context.Report(JsonSerializationResult::Tasks::ReadField, JsonSerializationResult::Outcomes::Skipped, "Skipping unrecognized field"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user