I receive an exception when deserializing RecurrenceInfo in a big project:
Newtonsoft.Json.JsonSerializationException: Cannot populate list type DevExpress.XtraScheduler.CustomFieldCollection at Newtonsoft.Json.... <<< omitted 20 Newtonsoft internal calls
The problem is reproducable with this MCVE:
RecurrenceInfo test = (RecurrenceInfo)RecurrenceBuilder.Weekly(DateTime.MinValue, DateTime.MaxValue).ByDay(WeekDays.Monday | WeekDays.Tuesday | WeekDays.Wednesday | WeekDays.Thursday | WeekDays.Friday).Build();
var copy = JsonConvert.DeserializeObject<RecurrenceInfo>(JsonConvert.SerializeObject(test));
I've noticed that in json there is this empty CustomFields
:
"Recurrence": {
...
"OccurrenceCount": 1,
"CustomFields": [],
"Id": "ef7ff4c3-9a3f-4cea-ab08-aa5f63e58c8c",
...
If I remove it from json, then there is no exception.
Because the project is big, it's a hassle to change something. So I am looking for a way to do it with minimum effort and affect on the rest.
Question
Given:
public class A
{
[JsonProperty]
public RecurrenceInfo B { get; set; }
}
How to exclude property B.CustomFields
from being serialized (or deserialized)? Ideally via some attribute(pseudocode):
[JsonProperty]
[CustomResolver(typeof(MyCustomResolver))]
public RecurrenceInfo B { get; set; }
I suspect the answer is "no, you have to specify custom resolver as deserializer settings" (I am trying to avoid that), but maybe someone sees something I don't or can think of a nice trick or a totally different solution?