TeamSirenix / odin-serializer

Fast, robust, powerful and extendible .NET serializer built for Unity
http://www.odininspector.com
Apache License 2.0
1.69k stars 193 forks source link

Does SerializationPolicies.Unity Serializes Auto-Properties? #2

Closed willnode closed 6 years ago

willnode commented 6 years ago

https://github.com/TeamSirenix/odin-serializer/blob/ecd5ee6cf3d71b654b62926f85e699a3db47d9f6/OdinSerializer/Core/Misc/SerializationPolicies.cs#L108-L112

However,

public class Sample : MonoBehaviour
{
    public class Foo
    {
        public int Bar { get; set; }
    }
    void Start()
    {
        Debug.Log(Encoding.UTF8.GetString(SerializationUtility.SerializeValue(new Foo(), DataFormat.JSON)));
    }
}

returns:

{
    "$id": 0,
    "$type": "0|Sample+Foo, Assembly-CSharp"
}

So then i'm not sure which one is correct.

TorVestergaard commented 6 years ago

As the documentation you quote states, the auto-property must be marked with [OdinSerialize] in order for the policy to serialize it.

willnode commented 6 years ago

Oops, you're right, I think I misunderstood the wording. Sorry!

Public fields and (fields or auto-properties marked with ..) <-- Wasn't aware to read this way.

TorVestergaard commented 6 years ago

That's perfectly understandable, really - we should probably add a comma in there to make the separation between the two cases clearer :)

TorVestergaard commented 6 years ago

I can add that I have now clarified the documentation for the Unity and Strict policies, so it should be better now.

willnode commented 6 years ago

I see, the doc is much better now. Thanks!