question

vutruongwork avatar image
vutruongwork asked

how to ignore properties when using Playfab Serializer

I use PluginContract.PlayFab_Serializer to serialize json but it also serializes properties as well. Is there anyway to ignore properties when serializing json using Playfab Serializer.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

vutruongwork avatar image vutruongwork commented ·

Is there anyone here can help me?

0 Likes 0 ·
Sarah Zhang avatar image
Sarah Zhang answered

Could you please provide the specific example? How did you use the PluginContract.PlayFab_Serializer in the client? And what is the expected behavior? Could you please provide the corresponding code snippet?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeremy Rose avatar image
Jeremy Rose answered

I am having the same issue. There appears to be no way to stop the SimpleJSON serializer from including properties. The normal C# way of adding a [System.NonSerialized] can not be added to a property only a field.

public class AClass
{
	public string ID = "";


	public int[] Data = new int[10];


	public int Property
	{
		get
		{
			return Data[0];
		}
		set
		{
			Data[0] = value;
		}
	}
}

Passing an instance of this class to say the ExecuteCloudScript as a dynamic property results in the basically the following JSON

["ID":"", "Data": [], "Property": 1]

Most serializers will not serialize properties without specifically including them. Looking at the SimpleJSON code I did not see any attributes to control this.

I would rather not have to make a separate class to copy to first before submitting.
Most of the point of this usage is to reduce the size of the actual json being sent. Be only serializing the the individual properties as a single json array of numbers.

I found ISerializer but this seem overkill to just exclude some properties that most other libraries have an attribute for.

Thanks
Jeremy

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.