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:
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Atom/RPI.Edit/Material/MaterialTypeSourceData.h>
|
||||
#include <AzCore/Serialization/Json/BaseJsonSerializer.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class ReflectContext;
|
||||
|
||||
namespace RPI
|
||||
{
|
||||
//! The property connection itself is rather simple, but we need this custom serializer to provide backward compatibility
|
||||
//! for when the "id" key was changed to "name". If the JSON serialization system is ever updated to provide built-in
|
||||
//! support for versioning, then we can probably remove this class.
|
||||
class JsonMaterialPropertyConnectionSerializer
|
||||
: public BaseJsonSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonMaterialPropertyConnectionSerializer, "{2B7F00CF-51F7-4409-9C0E-914E59696FB9}", BaseJsonSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
|
||||
JsonSerializationResult::Result Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
const void* defaultValue, const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
} // namespace RPI
|
||||
} // namespace AZ
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Atom/RPI.Edit/Material/MaterialTypeSourceData.h>
|
||||
#include <AzCore/Serialization/Json/BaseJsonSerializer.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class ReflectContext;
|
||||
|
||||
namespace RPI
|
||||
{
|
||||
//! The property group itself is rather simple, but we need this custom serializer to provide backward compatibility
|
||||
//! for when the "id" key was changed to "name". If the JSON serialization system is ever updated to provide built-in
|
||||
//! support for versioning, then we can probably remove this class.
|
||||
class JsonMaterialPropertyGroupSerializer
|
||||
: public BaseJsonSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonMaterialPropertyGroupSerializer, "{74C56BBC-2084-46AF-9393-04C2FBDF6B20}", BaseJsonSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
|
||||
JsonSerializationResult::Result Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
const void* defaultValue, const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
} // namespace RPI
|
||||
} // namespace AZ
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class JsonDeserializerContext;
|
||||
|
||||
namespace JsonSerializationResult
|
||||
{
|
||||
union ResultCode;
|
||||
}
|
||||
|
||||
namespace RPI
|
||||
{
|
||||
class MaterialTypeSourceData;
|
||||
@@ -35,6 +42,17 @@ namespace AZ
|
||||
//! @param filePath a relative path if document is provided, an absolute path if document is not provided.
|
||||
//! @param document the loaded json document.
|
||||
AZ::Outcome<MaterialTypeSourceData> LoadMaterialTypeSourceData(const AZStd::string& filePath, const rapidjson::Value* document = nullptr);
|
||||
|
||||
//! Utility function for custom JSON serializers to report results as "Skipped" when encountering keys that aren't recognized
|
||||
//! as part of the custom format.
|
||||
//! @param acceptedFieldNames an array of names that are recognized by the custom format
|
||||
//! @param acceptedFieldNameCount the number of elements in @acceptedFieldNames
|
||||
//! @param object the JSON object being loaded
|
||||
//! @param context the common JsonDeserializerContext that is central to the serialization process
|
||||
//! @param result the ResultCode that well be updated with the Outcomes "Skipped" if an unrecognized field is encountered
|
||||
void CheckForUnrecognizedJsonFields(
|
||||
const AZStd::string_view* acceptedFieldNames, uint32_t acceptedFieldNameCount,
|
||||
const rapidjson::Value& object, JsonDeserializerContext& context, JsonSerializationResult::ResultCode& result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user