I would like to ignore serialized private fields from json serialization, but it seems that [JsonIgnore] works only with public fields, it does not work with [SerializeField] private fields. Is there any other way to ignore those fields?
This is an example class:
using UnityEngine;
using Newtonsoft.Json;
[JsonObject(MemberSerialization.OptIn)]
public class ExampleObject : MonoBehaviour {
[JsonProperty]
private string property = "Property";
[JsonIgnore]
[SerializeField]
private string ignored = "Ignored";
}
Output
{"property":"Property","ignored":"Ignored"}
It still serializes the ignored field to json, even though I am using [JsonObject(MemberSerialization.OptIn)] on the class and [JsonIgnore] on the private field.
MemberSerialization.OptIn says that
"Only members marked with
JsonPropertyAttributeorSystem.Runtime.Serialization.DataMemberAttributeare serialized"
, but it also seems to include SerializeField attributes.
Edit: I am using JilleJr Newtonsoft.Json-for-Unity (github link) with JilleJr Newtonsoft.Json-for-Unity.Converters(github link)