Skip to content

Commit

Permalink
Add proper runtime JSON validation
Browse files Browse the repository at this point in the history
  • Loading branch information
arunoda committed Jul 31, 2021
1 parent b7d03b7 commit deac5f0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Refer to the following examples for more usage:<br/>
**For JSON**

* [Check for there's a key or not](https://blueprintue.com/blueprint/okwmyljw/)
* [Runtime JSON Validation](https://blueprintue.com/blueprint/foc1vk8h/)
* [Runtime JSON Validation](https://blueprintue.com/blueprint/dnpnrs8m/)

## Functional Test Suite

Expand Down
Binary file not shown.
Binary file modified UnrealFetchDevApp/Content/Tests/SimpleJson/SimpleJsonTests.umap
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ USimpleJsonValue* USimpleJson::MakeJson(FString InputJson)

TSharedRef<TJsonReader<>> Reader2 = TJsonReaderFactory<>::Create("{}");
FJsonSerializer::Deserialize(Reader2, ParsedJSON);
return USimpleJsonValue::Get(ParsedJSON);
USimpleJsonValue* InvalidJson = USimpleJsonValue::Get(ParsedJSON);
InvalidJson->InvalidJson = true;

return InvalidJson;
}

USimpleJsonValue* USimpleJson::MakeJsonNumber(float Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ bool USimpleJsonValue::IsNull()
return Original->IsNull();
}

bool USimpleJsonValue::IsValid()
{
return !InvalidJson;
}

USimpleJsonValue* USimpleJsonValue::Get(TSharedPtr<FJsonValue> Original)
{
USimpleJsonValue* JsonValue = NewObject<USimpleJsonValue>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ class FETCH_API USimpleJsonValue : public UObject
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Fetch | SimpleJsonValue")
bool IsNull();

UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Fetch | SimpleJsonValue")
bool IsValid();

static USimpleJsonValue* Get(TSharedPtr<FJsonValue> JsonValue);

public:
TSharedPtr<FJsonValue> Original;
bool InvalidJson = false;
};

0 comments on commit deac5f0

Please sign in to comment.