We have a need to serialize objects with versioning, so we are encapsulating them in an envelope:
protected void OnStateChanged(Object state)
{
var envelope = new WorkerStateData<Object>
{
StateVersion = workerConfig.CurrentStateVersion,
Value = state
};
String serializedState = JsonConvert.SerializeObject(envelope, new VersionConverter());
}
With one of our entities that need to be serialized, Newtonsoft is detecting a reference loop. I've confirmed that no such loop exists by forcing serialization ReferenceLoopHandling.Serialize
:
var serializeSettings = new JsonSerializerSettings();
serializeSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
String serialized = JsonConvert.SerializeObject(state, Formatting.Indented, serializeSettings);
This test serialization succeeds with no reference loop.
The problem is that there doesn't seem to be an overload of JsonConvert.SerializeObject
which accepts both JsonSerializerSettings
and JsonConverter[]
. Without having both of those pieces of functionality, I can't integrate this fix into our main code base.
Can anyone suggest another way to bypass the reference loop check?