NativeInterfaceJSStructSerializerBackend.cpp
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Engine/Source/Runtime/WebBrowser/Private/Native/NativeJSStructSerializerBackend.cpp
#include "Native/NativeInterfaceJSStructSerializerBackend.h"
#include "NativeInterfaceJSScripting.h"
#include "UObject/UnrealType.h"
#include "UObject/PropertyPortFlags.h"
#include "Templates/Casts.h"
void FNativeInterfaceJSStructSerializerBackend::WriteProperty(const FStructSerializerState& State, int32 ArrayIndex)
{
// The parent class serialzes UObjects as NULLs
if (State.FieldType == FObjectProperty::StaticClass())
{
WriteUObject(State, CastFieldChecked<FObjectProperty>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex));
}
// basic property type (json serializable)
else
{
FJsonStructSerializerBackend::WriteProperty(State, ArrayIndex);
}
}
void FNativeInterfaceJSStructSerializerBackend::WriteUObject(const FStructSerializerState& State, UObject* Value)
{
// Note this function uses WriteRawJSONValue to append non-json data to the output stream.
FString RawValue = Scripting->ConvertObject(Value);
if ((State.ValueProperty == nullptr) || (State.ValueProperty->ArrayDim > 1) || State.ValueProperty->GetOwner< FArrayProperty>())
{
GetWriter()->WriteRawJSONValue(RawValue);
}
else if (State.KeyProperty != nullptr)
{
FString KeyString;
State.KeyProperty->ExportTextItem(KeyString, State.KeyData, nullptr, nullptr, PPF_None);
GetWriter()->WriteRawJSONValue(KeyString, RawValue);
}
else
{
GetWriter()->WriteRawJSONValue(Scripting->GetBindingName(State.ValueProperty), RawValue);
}
}
FNativeInterfaceJSStructSerializerBackend::FNativeInterfaceJSStructSerializerBackend(TSharedRef<class FNativeInterfaceJSScripting> InScripting, FMemoryWriter& Writer)
: FJsonStructSerializerBackend(Writer, EStructSerializerBackendFlags::Default)
, Scripting(InScripting)
{
}