Skip to content

Commit

Permalink
Fix bug that membership functions had incorrect checks for JsonObject…
Browse files Browse the repository at this point in the history
… input.
  • Loading branch information
KGronek-Pubnub committed Nov 28, 2024
1 parent f873994 commit f8280b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,27 @@ bool UPubnubJsonUtilities::StringToJsonObject(FString JsonString, TSharedPtr<FJs
return FJsonSerializer::Deserialize(JsonReader, JsonObject);
}

bool UPubnubJsonUtilities::StringToJsonArray(FString JsonString, TArray<TSharedPtr<FJsonValue>>& OutArray)
{
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonString);
return FJsonSerializer::Deserialize(JsonReader, OutArray);
}

bool UPubnubJsonUtilities::IsCorrectJsonString(const FString InString, bool AllowSimpleTypes)
{
//A String is correct Json if it's a valid Json Object or Json Array
//A String is correct Json if it's a valid Json Object
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject);
if(StringToJsonObject(InString, JsonObject))
{
return true;
}

//or a Json Array
TArray<TSharedPtr<FJsonValue>> JsonArray;
if(StringToJsonArray(InString, JsonArray))
{
return true;
}

if(!AllowSimpleTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class PUBNUBLIBRARY_API UPubnubJsonUtilities : public UBlueprintFunctionLibrary
//Convert FString to JsonObject. Returns true if conversion was successful
static bool StringToJsonObject(FString JsonString, TSharedPtr<FJsonObject> &JsonObject);

//Convert FString to JsonArray. Returns true if conversion was successful
static bool StringToJsonArray(FString JsonString, TArray<TSharedPtr<FJsonValue>>& OutArray);

/**
* Checks if gives string can be converted to a json
* @param InString - String to check
Expand Down

0 comments on commit f8280b3

Please sign in to comment.