MetaSoul

Loading...
Searching...
No Matches
ESIOJConvert.h
Go to the documentation of this file.
1#pragma once
2
3#include "CoreMinimal.h"
4#include "UObject/Package.h"
5#include "UObject/ObjectMacros.h"
6#include "Runtime/Json/Public/Dom/JsonObject.h"
7#include "Runtime/Json/Public/Dom/JsonValue.h"
8#include "ESIOJConvert.generated.h"
9
10 struct FTrimmedKeyMap
11{
12 FString LongKey;
13 TMap<FString, TSharedPtr<FTrimmedKeyMap>> SubMap;
14
15 FString ToString();
16};
17
18UCLASS()
19class EMOSHAPESUBSYSTEM_API UESIOJConvert : public UObject
20{
21 GENERATED_BODY()
22 public:
23
24 //encode/decode json convenience wrappers
25 static FString ToJsonString(const TSharedPtr<FJsonObject>& JsonObject);
26 static FString ToJsonString(const TSharedPtr<FJsonValue>& JsonValue);
27 static FString ToJsonString(const TArray<TSharedPtr<FJsonValue>>& JsonValueArray);
28
29 static TSharedPtr<FJsonObject> ToJsonObject(const FString& JsonString);
30 static TSharedPtr<FJsonObject> MakeJsonObject();
31
32
33 //Structs
34
35 //Will trim names if specified as blueprint
36 static TSharedPtr<FJsonObject> ToJsonObject(UStruct* Struct, void* StructPtr, bool IsBlueprintStruct = false, bool BinaryStructCppSupport = false);
37
38 //Expects a JsonObject, if blueprint struct it will lengthen the names to fill properly
39 static bool JsonObjectToUStruct(TSharedPtr<FJsonObject> JsonObject, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct = false, bool BinaryStructCppSupport = false);
40
41 //Files - convenience read/write files
42 static bool JsonFileToUStruct(const FString& FilePath, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct = false);
43 static bool ToJsonFile(const FString& FilePath, UStruct* Struct, void* StructPtr, bool IsBlueprintStruct = false);
44
45
46 //typically from callbacks
47 static class UESJsonValue* ToEmoShapeJsonValue(const TArray<TSharedPtr<FJsonValue>>& JsonValueArray);
48
49 //Convenience overrides for JsonValues
50 static TSharedPtr<FJsonValue> ToJsonValue(const TSharedPtr<FJsonObject>& JsonObject);
51 static TSharedPtr<FJsonValue> ToJsonValue(const FString& StringValue);
52 static TSharedPtr<FJsonValue> ToJsonValue(double NumberValue);
53 static TSharedPtr<FJsonValue> ToJsonValue(bool BoolValue);
54 static TSharedPtr<FJsonValue> ToJsonValue(const TArray<uint8>& BinaryValue);
55 static TSharedPtr<FJsonValue> ToJsonValue(const TArray<TSharedPtr<FJsonValue>>& ArrayValue);
56
57 static TSharedPtr<FJsonValue> JsonStringToJsonValue(const FString& JsonString);
58 static TArray<TSharedPtr<FJsonValue>> JsonStringToJsonArray(const FString& JsonString);
59
60
61 //internal utility, exposed for modularity
62 static void TrimValueKeyNames(const TSharedPtr<FJsonValue>& JsonValue);
63 static bool TrimKey(const FString& InLongKey, FString& OutTrimmedKey);
64 static void SetTrimmedKeyMapForStruct(TSharedPtr<FTrimmedKeyMap>& InMap, UStruct* Struct);
65 static void SetTrimmedKeyMapForProp(TSharedPtr<FTrimmedKeyMap>& InMap, FProperty* ArrayInnerProp);
66 static void ReplaceJsonValueNamesWithMap(TSharedPtr<FJsonValue>& InValue, TSharedPtr<FTrimmedKeyMap> KeyMap);
67
68 static FString EnumToString(const FString& enumName, const int32 value);
69
70};
UESIOJConvert
Definition ESIOJConvert.h:20
UESJsonValue
Definition ESJsonValue.h:63
FTrimmedKeyMap
Definition ESIOJConvert.h:11
FTrimmedKeyMap::LongKey
FString LongKey
Definition ESIOJConvert.h:12
FTrimmedKeyMap::ToString
FString ToString()
Definition ESIOJConvert.cpp:541
FTrimmedKeyMap::SubMap
TMap< FString, TSharedPtr< FTrimmedKeyMap > > SubMap
Definition ESIOJConvert.h:13