Using FOnlineJsonSerializable on a struct

Hello,

I’m trying to serialize a very simple struct, but I’m guessing UE4’s preproccessor scripts are borking this.

My struct:

USTRUCT(BlueprintType)
struct FInventoryItemEntry : public FOnlineJsonSerializable
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Inventory")
	FString ItemId;

	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Inventory")
	int32 Quantity;

	FInventoryItemEntry() { }
	FInventoryItemEntry(FString id)
	{
		ItemId = id;
		Quantity = 1;
	}
	FInventoryItemEntry(FString id, int32 count)
	{
		ItemId = id;
		Quantity = count;
	}

	BEGIN_ONLINE_JSON_SERIALIZER_FLAT
		ONLINE_JSON_SERIALIZE("ItemId", ItemId);
		ONLINE_JSON_SERIALIZE("Quantity", Quantity);
	END_ONLINE_JSON_SERIALIZER_FLAT
};

My compilation error:

Inventory.h(59): error : In Inventory: 'struct': Can't find struct 'FOnlineJsonSerializable'

Just below this struct I have a class that extends FOnlineJsonSerializable, and that compiles just fine, so it definitely has a reference to FOnlineJsonSerializable, I’m guessing this is a bug with the preprocessors.

Has anyone seen this or found a workaround? This is currently blocking me, and I’d rather not have to write a custom serializer method.

Thanks for any help!

Bumping…

Hello? Epic?

Yay for Epic’s wonderful support. Just switched to using a UObject instead. Yucky, wasteful hack for what we need, but quicker than waiting for a reply.

This is an old question now, but I ran into this issue and found the problem and an alternate solution.
The issue is that the type is not a USTRUCT, and so attempting to make a new USTRUCT that inherits from it will confuse the preprocessor.

TL;DR: It can’t find the struct because it hasn’t preprocessed it.

If you absolutely need the type to take advantage of the preprocessor (eg. make it exposed to Blueprint), you can make it a UObject inheriting class.
Eg.

UCLASS(BlueprintType)
class UMyJsonSerializable : public FOnlineJsonSerializable, public UObject

But if you don’t need your type to take advantage of the preprocessor, just making it a regular old struct will do the job. Eg.

struct FMyJsonSerializable : public FOnlineJsonSerializable

You can still use it as you would any other C++ struct, because that’s exactly what it is. You don’t even have to use the prefix if you don’t want to, the preprocessor won’t enforce it.

Hope this helps someone, happy coding.