Closed xmedeko closed 5 years ago
ShowReadOnlyProperties = false
?
Yes, ShowReadOnlyProperties = false
. I've checked the Reflection.GetGetters
and the ShowReadOnlyProperties
param is not used for fields.
Thanks, will fix.
Try v2.2.5
Works well, thanks for the quick fix.
@mgholam Serialization is OK. But deserialization still deserialize read-only fields if they are in JSON. I think the chage should be in Reflection.CreateSetField(..)
, probably something like:
if (fieldInfo.IsInitOnly)
return null;
Hmm... wouldn't you want to have it set if it is in the json string (and have the serializer controls this)?
Well, if you serialize/deserialize same class, then it's like you write. But consider these scenarios:
Also, check that Reflection.CreateSetMethod(..)
returns null for read-only properties. IMO Reflection.CreateSetField(..)
should behave consistently.
Check the latest commit.
But no ShowReadOnlyProperties
is involved in the condition. Probably should be:
if (ShowReadOnlyProperties || f.IsInitOnly == false)
d.setter = Reflection.CreateSetField(type, f);
For that, it will have to happen higher up the stack, since the setters are being cached (like the serializer).
I have set
ShowReadOnlyProperties = false
, but the readonly fields are serialized. I havepublic static readonly MyConstantClass MyConstant
filed and this field is serialized, too.Please, do not serialize readonly field and do not serialize static fields/properties/methods. Thanks