Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::BaseJsonSerializer Class Reference

#include <BaseJsonSerializer.h>

Inherited by AZ::BaseJsonIntegerSerializer, AZ::BaseJsonMatrixSerializer, AZ::BaseJsonVectorSerializer, AZ::Data::AssetJsonSerializer, AZ::EnumConstantJsonSerializer, AZ::JsonAnySerializer, AZ::JsonArraySerializer, AZ::JsonBasicContainerSerializer, AZ::JsonBoolSerializer, AZ::JsonByteStreamSerializer, AZ::JsonColorSerializer, AZ::JsonConfigurableStackSerializer, AZ::JsonDoubleSerializer, AZ::JsonEntityIdSerializer, AZ::JsonEntitySerializer, AZ::JsonFloatSerializer, AZ::JsonMapSerializer, AZ::JsonOSStringSerializer, AZ::JsonPathSerializer, AZ::JsonSmartPointerSerializer, AZ::JsonStringSerializer, AZ::JsonTransformSerializer, AZ::JsonTupleSerializer, AZ::JsonUnorderedSetContainerSerializer, AZ::JsonUnsupportedTypesSerializer, AZ::JsonUuidSerializer, AZ::NameJsonSerializer, and AZ::ScriptPropertySerializer.

Public Types

enum class  ContinuationFlags {
  None = 0 , ResolvePointer = 1 << 0 , ReplaceDefault = 1 << 1 , LoadAsNewInstance = 1 << 2 ,
  IgnoreTypeSerializer = 1 << 3
}
 
enum class  OperationFlags { None = 0 , ManualDefault = 1 << 0 , InitializeNewInstance = 1 << 1 }
 

Public Member Functions

 AZ_RTTI (BaseJsonSerializer, "{7291FFDC-D339-40B5-BB26-EA067A327B21}")
 
virtual JsonSerializationResult::Result Load (void *outputValue, const Uuid &outputValueTypeId, const rapidjson::Value &inputValue, JsonDeserializerContext &context)
 
virtual JsonSerializationResult::Result Store (rapidjson::Value &outputValue, const void *inputValue, const void *defaultValue, const Uuid &valueTypeId, JsonSerializerContext &context)
 
virtual OperationFlags GetOperationsFlags () const
 Returns the operation flags which tells the Json Serialization how this custom json serializer can be used.
 

Protected Member Functions

JsonSerializationResult::ResultCode ContinueLoading (void *object, const Uuid &typeId, const rapidjson::Value &value, JsonDeserializerContext &context, ContinuationFlags flags=ContinuationFlags::None)
 
JsonSerializationResult::ResultCode ContinueStoring (rapidjson::Value &output, const void *object, const void *defaultObject, const Uuid &typeId, JsonSerializerContext &context, ContinuationFlags flags=ContinuationFlags::None)
 
JsonSerializationResult::ResultCode LoadTypeId (Uuid &typeId, const rapidjson::Value &input, JsonDeserializerContext &context, const Uuid *baseTypeId=nullptr, bool *isExplicit=nullptr)
 
JsonSerializationResult::ResultCode StoreTypeId (rapidjson::Value &output, const Uuid &typeId, JsonSerializerContext &context)
 
JsonSerializationResult::ResultCode ContinueLoadingFromJsonObjectField (void *object, const Uuid &typeId, const rapidjson::Value &value, rapidjson::Value::StringRefType memberName, JsonDeserializerContext &context, ContinuationFlags flags=ContinuationFlags::None)
 Helper function similar to ContinueLoading, but loads the data as a member of 'value' rather than 'value' itself, if it exists.
 
JsonSerializationResult::ResultCode ContinueStoringToJsonObjectField (rapidjson::Value &output, rapidjson::Value::StringRefType newMemberName, const void *object, const void *defaultObject, const Uuid &typeId, JsonSerializerContext &context, ContinuationFlags flags=ContinuationFlags::None)
 Helper function similar to ContinueStoring, but stores the data as a member of 'output' rather than overwriting 'output'.
 
bool IsExplicitDefault (const rapidjson::Value &value)
 
rapidjson::Value GetExplicitDefault ()
 

Detailed Description

The abstract class for primitive Json Serializers. It is intentionally not templated, and uses void* for output value parameters.

Member Enumeration Documentation

◆ ContinuationFlags

Enumerator
ResolvePointer 

No extra flags.

ReplaceDefault 

The pointer passed in contains a pointer. The (de)serializer will attempt to resolve to an instance.

LoadAsNewInstance 

The default value provided for storing will be replaced with a newly created one.

IgnoreTypeSerializer 

Treats the value as if it's a newly created instance. This may trigger serializers marked with OperationFlags::InitializeNewInstance. Used for instance by pointers or new instances added to an array.

◆ OperationFlags

Enumerator
ManualDefault 

No flags that control how the custom json serializer is used.

InitializeNewInstance 

Even if an (explicit) default is found the custom json serializer will still be called.

Member Function Documentation

◆ ContinueLoading()

JsonSerializationResult::ResultCode AZ::BaseJsonSerializer::ContinueLoading ( void *  object,
const Uuid typeId,
const rapidjson::Value &  value,
JsonDeserializerContext context,
ContinuationFlags  flags = ContinuationFlags::None 
)
protected

Continues loading of a (sub)value. Use this function to load member variables for instance. This is more optimal than directly calling the json serialization.

Parameters
objectPointer to the object where the data will be loaded into.
typeIdType id of the object passed in.
valueThe value in the JSON document where the deserializer will start reading data from.
contextThe context used during deserialization. Use the value passed in from Load.

◆ ContinueStoring()

JsonSerializationResult::ResultCode AZ::BaseJsonSerializer::ContinueStoring ( rapidjson::Value &  output,
const void *  object,
const void *  defaultObject,
const Uuid typeId,
JsonSerializerContext context,
ContinuationFlags  flags = ContinuationFlags::None 
)
protected

Continues storing of a (sub)value. Use this function to store member variables for instance. This is more optimal than directly calling the json serialization.

Parameters
outputThe value in the json document where the converted data will start writing to.
allocatorThe memory allocator used by RapidJSON to create the json document.
objectPointer to the object that will be read from for values to convert.
defaultObjectPointer to a default object used to compare the object to in order to determine if values are defaulted or not. This argument can be null, in which case a temporary default may be created if required by the settings.
typeIdThe type id of the object and default object.
contextThe context used during serialization. Use the value passed in from Store.

◆ GetExplicitDefault()

rapidjson::Value AZ::BaseJsonSerializer::GetExplicitDefault ( )
protected

Gets a value to represent an explicit default. This useful for containers where not storing anything as a default would mean a slot wouldn't be used so something has to be added to represent the fully default target.

◆ GetOperationsFlags()

virtual OperationFlags AZ::BaseJsonSerializer::GetOperationsFlags ( ) const
virtual

◆ IsExplicitDefault()

bool AZ::BaseJsonSerializer::IsExplicitDefault ( const rapidjson::Value &  value)
protected

Checks if a value is an explicit default. This useful for containers where not storing anything as a default would mean a slot wouldn't be used so something has to be added to represent the fully default target.

◆ Load()

virtual JsonSerializationResult::Result AZ::BaseJsonSerializer::Load ( void *  outputValue,
const Uuid outputValueTypeId,
const rapidjson::Value &  inputValue,
JsonDeserializerContext context 
)
virtual

Transforms the data from the rapidjson Value to outputValue, if the conversion is possible and supported. The serializer is responsible for casting to the proper type and safely writing to the outputValue memory.

Note
The default implementation is to load the object ignoring a custom serializers for the type, which allows for custom serializers to modify the object after all default loading has occurred.

Reimplemented in AZ::Data::AssetJsonSerializer, AZ::JsonEntityIdSerializer, AZ::JsonEntitySerializer, AZ::JsonColorSerializer, AZ::JsonMatrix3x3Serializer, AZ::JsonMatrix3x4Serializer, AZ::JsonMatrix4x4Serializer, AZ::JsonVector2Serializer, AZ::JsonVector3Serializer, AZ::JsonVector4Serializer, AZ::JsonQuaternionSerializer, AZ::JsonTransformSerializer, AZ::JsonUuidSerializer, AZ::NameJsonSerializer, AZ::EnumConstantJsonSerializer, AZ::JsonAnySerializer, AZ::JsonArraySerializer, AZ::JsonBasicContainerSerializer, AZ::JsonBoolSerializer, AZ::JsonByteStreamSerializer, AZ::JsonDoubleSerializer, AZ::JsonFloatSerializer, AZ::JsonCharSerializer, AZ::JsonShortSerializer, AZ::JsonIntSerializer, AZ::JsonLongSerializer, AZ::JsonLongLongSerializer, AZ::JsonUnsignedCharSerializer, AZ::JsonUnsignedShortSerializer, AZ::JsonUnsignedIntSerializer, AZ::JsonUnsignedLongSerializer, AZ::JsonUnsignedLongLongSerializer, AZ::JsonMapSerializer, AZ::JsonPathSerializer, AZ::JsonSmartPointerSerializer, AZ::JsonStringSerializer, AZ::JsonOSStringSerializer, AZ::JsonTupleSerializer, AZ::JsonUnorderedSetContainerSerializer, AZ::JsonUnsupportedTypesSerializer, and AZ::JsonConfigurableStackSerializer.

◆ LoadTypeId()

JsonSerializationResult::ResultCode AZ::BaseJsonSerializer::LoadTypeId ( Uuid typeId,
const rapidjson::Value &  input,
JsonDeserializerContext context,
const Uuid baseTypeId = nullptr,
bool *  isExplicit = nullptr 
)
protected

Retrieves the type id from a json object or json string.

Parameters
typeIdThe retrieved type id.
inputThe json object to read type information from. This call will fail if input is not an object.
contextThe context used during serialization. Use the value passed in from Store.
baseTypeIdAn optional base type that the target type id is expected to inherit from. If two or more types share the same then the baseTypeId is used to disambiguate between candidates.
isExplicitAn optional boolean to indicate if the type id was explicitly (true) declared in the json file or that it was derived from the provided information (false).

◆ Store()

virtual JsonSerializationResult::Result AZ::BaseJsonSerializer::Store ( rapidjson::Value &  outputValue,
const void *  inputValue,
const void *  defaultValue,
const Uuid valueTypeId,
JsonSerializerContext context 
)
virtual

Write the input value to a rapidjson value if the default value is not null and doesn't match the input value, otherwise an error is returned and sets the rapidjson value to a null value.

Note
The default implementation is to store the object ignoring custom serializers.

Reimplemented in AZ::Data::AssetJsonSerializer, AZ::JsonEntityIdSerializer, AZ::JsonEntitySerializer, AZ::JsonColorSerializer, AZ::JsonMatrix3x3Serializer, AZ::JsonMatrix3x4Serializer, AZ::JsonMatrix4x4Serializer, AZ::JsonVector2Serializer, AZ::JsonVector3Serializer, AZ::JsonVector4Serializer, AZ::JsonQuaternionSerializer, AZ::JsonTransformSerializer, AZ::JsonUuidSerializer, AZ::NameJsonSerializer, AZ::EnumConstantJsonSerializer, AZ::JsonAnySerializer, AZ::JsonArraySerializer, AZ::JsonBasicContainerSerializer, AZ::JsonBoolSerializer, AZ::JsonByteStreamSerializer, AZ::JsonDoubleSerializer, AZ::JsonFloatSerializer, AZ::JsonCharSerializer, AZ::JsonShortSerializer, AZ::JsonIntSerializer, AZ::JsonLongSerializer, AZ::JsonLongLongSerializer, AZ::JsonUnsignedCharSerializer, AZ::JsonUnsignedShortSerializer, AZ::JsonUnsignedIntSerializer, AZ::JsonUnsignedLongSerializer, AZ::JsonUnsignedLongLongSerializer, AZ::JsonMapSerializer, AZ::JsonUnorderedMapSerializer, AZ::JsonUnorderedMapSerializer, AZ::JsonUnorderedMultiMapSerializer, AZ::JsonUnorderedMultiMapSerializer, AZ::JsonPathSerializer, AZ::JsonSmartPointerSerializer, AZ::JsonStringSerializer, AZ::JsonOSStringSerializer, AZ::JsonTupleSerializer, AZ::JsonUnorderedSetContainerSerializer, AZ::JsonUnsupportedTypesSerializer, and AZ::JsonConfigurableStackSerializer.

◆ StoreTypeId()

JsonSerializationResult::ResultCode AZ::BaseJsonSerializer::StoreTypeId ( rapidjson::Value &  output,
const Uuid typeId,
JsonSerializerContext context 
)
protected

Stores the name of the type id or if there are conflicts the type's uuid.

Parameters
outputThe json value that will receive the converted type id.
typIdThe Type id to store.
contextThe context used during serialization. Use the value passed in from Store.

The documentation for this class was generated from the following file: