question

Niall Muldoon avatar image
Niall Muldoon asked

ISerializerPlugin Questions

Hi,

I have started using your provided JSON serializer via the PluginManager, example usage below:

m_serializer = PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer);
string json = m_serializer.SerializeObject (gameData);
gameData = m_serializer.DeserializeObject<GameData> (json);

Is it possible to serialise private fields? Right now it seems that they have to be public. [SerializeField] doesn't seem to work.

It serialises public properties which I find rather strange, how can this be disabled so I do not end up storing data twice (once in the field and once in the Property)?

Thank you,

10 |1200

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

1 Answer

·
Hernando avatar image
Hernando answered

It must be clarified that [SerializeField] is different from [Serializable]. [SerializeField] makes a field display in the Inspector and causes it to be saved, but [Serializable] attribute to a type to indicate that instances of this type can be serialized as a stream of bytes. So they have nothing with each other, and you would be not using [SerializeField] in the process of converting an object into JSON.

3 comments
10 |1200

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

Niall Muldoon avatar image Niall Muldoon commented ·

Hi,

When using Unity's JSONUtility, [SerializeField] does affect whether the field is serialised to JSON, I am looking for equivaleent fucntioanlity essentially.

[Serializable] is not applicable for individual fields so does not help me with my original questions.

Please let me know best practice for how to proceed based on the two questions in my original post.

Thank you,

Niall

0 Likes 0 ·
Andy avatar image Andy ♦♦ Niall Muldoon commented ·

The default implementation of ISerializerPlugin within the Unity SDK uses SimpleJSON. It, to the best of my knowledge, does not support serializing private members. If you'd like to add support for serializing private fields, you'll need to implement your own ISerializerPlugin and call PluginManager.SetPlugin to switch to it.

Depending on how you're building in Unity, you might be able to use JSON .Net as the base.

0 Likes 0 ·
vutruongwork avatar image vutruongwork commented ·

Same question: Is there anyway to ignore property serialization?

0 Likes 0 ·

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.