I'm building a game scene editor with prefab type objects and am using Newtonsofts Json.NET to save my scenes. When saving the scene, I only want to save an objects changed values from the original prefab. Thus I'd like to be able to specify a manual check method for the Json.Net serializer where I can perform a check if the value is changed before deciding to write it to the file or not.
I understand I can avoid writing to the JSON if I use the [DefaultValue()]
attribute and DefaultValueHandling = DefaultValueHandling.Ignore
, however since the value can be different from a default, this approach won't work for me. I would like to be able to manually specify which values to write or not depending on their value and situation.
Preferably if I could be supplied a method such as bool shouldWriteMember(object obj, MemberInfo info)
that everything gets passet through that I could attach to the serializer somehow.
Is there any way to do this in Json.NET that I'm missing? Thanks!