Possible Serialization / Deserialization inconsistency

Gents,

Was pulling my hair out a few days ago trying to understand why my objects were getting persisted to storage, but when reading those same objects back, I wasn't seeing my collection.

As expected, if I place the [Serializable] attribute on my storage class, any of the typical fields will get serialized and persisted to storage.
However, UNLESS I have [JsonProperty] attribute on the individual fields, the deserialization process misses them and returns null.

In particular, a HashSet field would be stored w/o [JsonProperty] attribute, but upon deserialization, it's null.
Add the attribute, and it returns the value found in the persisted file.

For some reason, I missed this field - but what was particularly maddening was other class fields that didn't have the [JsonProperty] attribute were getting read back - e.g. booleans and ints.

I haven't dug into the backend, but it does seem like inconsistent behavior. 

One thing is for certain - I wont be soon forgetting to put the attributes on my fields!

Issue with making those fields properties?
By default Newtonsoft.Json doesn't serialize fields.

Vw2nThHWKCrkxji.png austinv900

Issue with making those fields properties?
By default Newtonsoft.Json doesn't serialize fields.

Apparently it does - WITHOUT [JsonProperty] applied to the field, it DOES serialize it.  The inconsistency is that upon DESERIALIZATION, it will not deserialize it unless it has the attribute, [JsonProperty] applied. 

Hence, the use of the word, 'inconsistency'

ZA9xLTWkWP5paMn.jpg Lurch5250

Apparently it does - WITHOUT [JsonProperty] applied to the field, it DOES serialize it.  The inconsistency is that upon DESERIALIZATION, it will not deserialize it unless it has the attribute, [JsonProperty] applied. 

Hence, the use of the word, 'inconsistency'

I'm sure that might be defined in the default settings somewhere.
Vw2nThHWKCrkxji.png austinv900
I'm sure that might be defined in the default settings somewhere.

Haven't found anything looking like default settings. I mentioned this in a sprint the other day and the convo went into why putting the attribute [Serilaizable] on any class was even necessary to begin with. Ha. Typical devs...

ZA9xLTWkWP5paMn.jpg Lurch5250

Haven't found anything looking like default settings. I mentioned this in a sprint the other day and the convo went into why putting the attribute [Serilaizable] on any class was even necessary to begin with. Ha. Typical devs...

https://www.newtonsoft.com/json/help/html/DefaultSettings.htm


Just make sure you store the old defaults and restore them on unload.