UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
JsonStringifyImpl.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "Containers/Array.h"
10
11class FArrayProperty;
12class FSetProperty;
13class FMapProperty;
15class UPropertyBag;
16
17namespace UE::Private
18{
19
20struct FPrettyJsonWriter;
22
24{
26
27 // Writes and returns the provided root objects as a UTF8 encode Json string, honoring
28 // options specified in our constructor:
30
31 // Helpers for writing to an object to a specific FJsonWriter, or specific FArchive. These
32 // are used by the native stream serializers and native structured serializers respectively -
33 // WriteObjectAsJsonToWriter is also used as objects are encountered in reflected properties.
34 // The owning object must be provided so that we can determine whether to write InObject as a
35 // peer reference, or inline. For root level serialization use ToJson():
36 void WriteObjectAsJsonToWriter(const UObject* OwningObject, const UObject* InObject, TSharedRef<FJsonWriter> WriterToUse);
37 void WriteObjectAsJsonToArchive(const UObject* OwningObject, const UObject* InObject, FArchive* ArchiveToUse, int32 InitialIndentLevel);
38
39 // Helper to improve support for FField references, which are not uncommon:
41
42private:
43 void ToJsonBytes();
44 void WriteObjectToJson(const UObject* Object);
45
46 // Utility for unreflected UObject data - name, class, and flags - this
47 // data is placed into a special key for a loader that needs to order
48 // UObject construction (find archetypes, UClasses, UStructs, etc):
49 void WriteNativeObjectData();
50 void WriteIndirectlyReferencedContainedObjects(const UObject* ForObject);
51 FUtf8String WriteObjectReference(const UObject* Object) const;
52 FUtf8String WriteFieldReference(const FField* Value) const;
53
54 void WriteIdentifierAndValueToJson(const void* Container, const void* DefaultContainer, const FProperty* Property);
55 void WriteValueToJson(const void* Value, const void* DefaultValue, const FProperty* Property);
56 void WriteIntrinsicToJson(const void* Value, const FProperty* Property);
57
58 // May want to expose WriteStructToJsonWithIdentifier for users to manually write USTRUCT instances into json:
59 void WriteStructToJsonWithIdentifier(const TCHAR* Identifier, const void* StructInstance, const void* DefaultInstance, const UScriptStruct* Struct, const UScriptStruct* DefaultStruct);
60 void WriteStructToJson(const void* StructInstance, const void* DefaultInstance, const UScriptStruct* Struct, const UScriptStruct* DefaultStruct);
61 void WriteArrayToJson(const void* ArrayInstance, const FArrayProperty* Array);
62 void WriteSetToJson(const void* SetInstance, const FSetProperty* SetProperty);
63 void WriteMapToJson(const void* MapInstance, const FMapProperty* MapProperty);
64 void WriteOptionalToJson(const void* OptionalInstnace, const FOptionalProperty* OptionalProperty);
65 void WritePropertyBagDescToJson(const UPropertyBag* PropertyBag);
66
67 TArray<uint8> SerialDataToJson(const UObject* Object, int32 InitialIndentLevel);
68#if WITH_TEXT_ARCHIVE_SUPPORT
69 TArray<uint8> StructuredDataToJson(const UObject* Object, int32 InitialIndentLevel);
70#endif// WITH_TEXT_ARCHIVE_SUPPORT
71
72 void WritePackageSummary();
73
74 bool IsDeltaEncoding() const;
75 bool ShouldWritePackageSummary() const;
76
77 const FJsonStringifyOptions& WriteOptions;
78
79 TArray<uint8> Result;
80 FMemoryWriter MemoryWriter;
81
82 // helper for enqueuing writes that may not need to be applied, e.g. if there
83 // are values that match the default value we won't write out the enclosing scope:
84 struct FPendingScope
85 {
86 FPendingScope(FJsonStringifyImpl* To, const TFunction<void()>& Prefix);
87 FPendingScope(FJsonStringifyImpl* To, const TFunction<void()>& Prefix, const TFunction<void()>& Postfix);
88 ~FPendingScope();
89 void Apply();
90 private:
91 FJsonStringifyImpl* Owner = nullptr;
92 FPendingScope* Outer = nullptr;
93 TFunction<void()> PendingPrefix;
94 TOptional<TFunction<void()>> PendingPostfix;
95
96 bool bHasBeenApplied = false;
97
98 FPendingScope(const FPendingScope& RHS) = delete;
99 FPendingScope(FPendingScope&& RHS) = delete;
100 FPendingScope& operator=(const FPendingScope& RHS) = delete;
101 FPendingScope& operator=(FPendingScope&& RHS) = delete;
102 };
103 FPendingScope* CurrentScope = nullptr;
104
106
107 const UObject* CurrentObject;
108 TArray<const UObject*> RootObjects;
109 TSet<const UObject*> ObjectsToExport;
110 TSet<const UObject*> ObjectsExported;
111
112 TArray<FCustomVersion> Versions;
113};
114
115}
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
TSharedRef< TJsonWriter< TCHAR, TPrettyJsonPrintPolicy< TCHAR > > > FPrettyJsonWriter
Definition PerfCountersModule.h:24
Definition Archive.h:1208
Definition UnrealType.h:3702
Definition Field.h:556
Definition UnrealType.h:3843
Definition MemoryWriter.h:101
Definition PropertyOptional.h:185
Definition UnrealType.h:174
Definition UnrealType.h:4028
Definition Array.h:670
Definition AndroidPlatformMisc.h:14
Definition Object.h:95
Definition PropertyBag.h:1309
Definition Class.h:1720
Definition PackageReader.cpp:44
Definition Stringify.h:26
Definition Optional.h:131
Definition JsonStringifyImpl.h:24
void WriteObjectAsJsonToArchive(const UObject *OwningObject, const UObject *InObject, FArchive *ArchiveToUse, int32 InitialIndentLevel)
Definition JsonStringifyImpl.cpp:297
void WriteFieldReferenceTo(const UObject *OwningObject, const FField *Value, TSharedRef< FJsonWriter > WriterToUse)
Definition JsonStringifyImpl.cpp:292
FUtf8String ToJson()
Definition JsonStringifyImpl.cpp:258
void WriteObjectAsJsonToWriter(const UObject *OwningObject, const UObject *InObject, TSharedRef< FJsonWriter > WriterToUse)
Definition JsonStringifyImpl.cpp:268
Definition PrettyJsonWriter.h:21