I’m making use of the VaRest Plugin for JSON formatting, but it seems like a lot of the functionalities are internalized.
Right now, it only supports REST and file as JSON sources. Given that new protocols like Websockets and MQTT are being released in Unreal Engine, I wanted to try to expose the functionality of VaRest to convert a JSON string to a VaRest JSON object.
I’ve edited the base plugin and tried to add this functionality as follows:
VaRestJsonLibrary.h
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "VaRestJsonObject.h"
#include "VaRestJsonLibrary.generated.h"
UCLASS()
class VAREST_API UVaRestJsonLibrary : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()
public:
/** Create new JSON object */
UFUNCTION(BlueprintCallable, Category = "VaRest|JSON")
static UVaRestJsonObject* ConstructJsonObject(UObject* WorldContextObject);
/** Convert a raw JSON string into a VaRestJsonObject */
UFUNCTION(BlueprintCallable, Category = "VaRest|JSON")
static UVaRestJsonObject* ParseJsonStringToVaRestObject(const FString& JsonString);
};
VaRestJsonLibrary.cpp
#include "VaRestJsonLibrary.h"
#include "Dom/JsonObject.h"
#include "Serialization/JsonReader.h"
#include "Serialization/JsonSerializer.h"
#include "VaRestJsonObject.h"
UVaRestJsonLibrary::UVaRestJsonLibrary(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
UVaRestJsonObject* UVaRestJsonLibrary::ConstructJsonObject(UObject* WorldContextObject)
{
return NewObject<UVaRestJsonObject>(WorldContextObject);
}
UVaRestJsonObject* UVaRestJsonLibrary::ParseJsonStringToVaRestObject(const FString& JsonString)
{
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(JsonString);
TSharedPtr<FJsonObject> JsonParsed;
if (!FJsonSerializer::Deserialize(Reader, JsonParsed) || !JsonParsed.IsValid())
{
UE_LOG(LogTemp, Warning, TEXT("ParseJsonStringToVaRestObject: Failed to parse JSON"));
return nullptr;
}
UVaRestJsonObject* VaRestObject = NewObject<UVaRestJsonObject>();
VaRestObject->SetRootObject(JsonParsed); // Ensure this is accessible
return VaRestObject;
}
I’ve ensured that the Marketplace plugin is removed, and this altered plugin is being used. But ParseJsonStringToVaRestObject still doesn’t show up in the Blueprint for me.
Is there something I’m missing? Is there some other files that need to be updated, or the plugin needs to be rebuilt somehow?
Thanks in advance!