// Modifications Copyright 2018-current Getnamo. All Rights Reserved #pragma once #include "CoreMinimal.h" #include "UObject/Package.h" #include "UObject/ObjectMacros.h" #include "Runtime/Json/Public/Dom/JsonObject.h" #include "Runtime/Json/Public/Dom/JsonValue.h" #include "SIOJConvert.generated.h" struct FTrimmedKeyMap { FString LongKey; TMap> SubMap; FString ToString(); }; /** * */ UCLASS() class SIOJSON_API USIOJConvert : public UObject { GENERATED_BODY() public: //encode/decode json convenience wrappers static FString ToJsonString(const TSharedPtr& JsonObject); static FString ToJsonString(const TSharedPtr& JsonValue); static FString ToJsonString(const TArray>& JsonValueArray); static TSharedPtr ToJsonObject(const FString& JsonString); static TSharedPtr MakeJsonObject(); //Structs //Will trim names if specified as blueprint static TSharedPtr ToJsonObject(UStruct* Struct, void* StructPtr, bool IsBlueprintStruct = false, bool BinaryStructCppSupport = false); //Expects a JsonObject, if blueprint struct it will lengthen the names to fill properly static bool JsonObjectToUStruct(TSharedPtr JsonObject, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct = false, bool BinaryStructCppSupport = false); //Files - convenience read/write files static bool JsonFileToUStruct(const FString& FilePath, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct = false); static bool ToJsonFile(const FString& FilePath, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct = false); static bool StructToBytes(UStruct* Struct, void* StructPtr, TArray& OutBytes, bool IsBlueprintStruct = false); static bool BytesToStruct(const TArray& InBytes, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct = false); //typically from callbacks static class USIOJsonValue* ToSIOJsonValue(const TArray>& JsonValueArray); //Convenience overrides for JsonValues static TSharedPtr ToJsonValue(const TSharedPtr& JsonObject); static TSharedPtr ToJsonValue(const FString& StringValue); static TSharedPtr ToJsonValue(double NumberValue); static TSharedPtr ToJsonValue(bool BoolValue); static TSharedPtr ToJsonValue(const TArray& BinaryValue); static TSharedPtr ToJsonValue(const TArray>& ArrayValue); static TSharedPtr JsonStringToJsonValue(const FString& JsonString); static TArray> JsonStringToJsonArray(const FString& JsonString); //internal utility, exposed for modularity static void TrimValueKeyNames(const TSharedPtr& JsonValue); static bool TrimKey(const FString& InLongKey, FString& OutTrimmedKey); static void SetTrimmedKeyMapForStruct(TSharedPtr& InMap, UStruct* Struct); static void SetTrimmedKeyMapForProp(TSharedPtr& InMap, FProperty* ArrayInnerProp); static void ReplaceJsonValueNamesWithMap(TSharedPtr& InValue, TSharedPtr KeyMap); };