Hello,
I have JSON files stored in memory via FJsonObject that I am using to convert to UObjects as required at runtime. This works totally fine the first time but on and after the second attempt the conversion fails. This is because the code shown below removes the ObjectClassNameKey from the JSON object at runtime, I assume this is done to avoid an error downstream when converting the JSON to a UObject or something like that? Couldn’t this be fixed by simply ignoring this field instead?
It becomes painful if you want to create a new UObject from the same in memory JSON file you can’t because now that in memory JSON file is not longer compatible for deserialisation and the only options you are left with are to re-create the in memory JSON file or to duplicate the UObject after you’ve created the first instance, neither of which are ideal solutions when I have what should be a perfectly good JSON object in memory already.
Could you let me know if this is something that you would consider changing?
Cheers!
// If a specific subclass was stored in the JSON, use that instead of the PropertyClass
FString ClassString = Obj->GetStringField(ObjectClassNameKey);
Obj->RemoveField(ObjectClassNameKey);
if (!ClassString.IsEmpty())
{
UClass* FoundClass = FPackageName::IsShortPackageName(ClassString) ? FindFirstObject<UClass>(*ClassString) : LoadClass<UObject>(nullptr, *ClassString);
if (FoundClass)
{
PropertyClass = FoundClass;
}
}
[Attachment Removed]