Newtonsoft Json.NET ReferenceLoopHandling and JavascriptDateTimeConverter

c#, datetime, json.net

Solution

You specify your `JavaScriptDateTimeConverter` inside the `JsonSerializerSettings`' with the `Converters` property:

var json = JsonConvert.SerializeObject(this.Data, new JsonSerializerSettings()
{
    Converters = new List<JsonConverter> { new JavaScriptDateTimeConverter() },
    ReferenceLoopHandling = ReferenceLoopHandling.Serialize
});

Actually the overload which takes the `JsonConverter` array internally creates a `JsonSerializerSettings` and sets its Converters property.

Problem

I need Json.NET to serialize using both JavaScriptDateTimeConverter and ReferenceLoopHandling.Ignore. None of the signatures on JsonConvert.SerializeObject allow setting both of these setting, as far as I can tell. I can do: ``` var json = JsonConvert.SerializeObject(this.Data, new JavaScriptDateTimeConverter()); ``` Or I can do: ``` var json = JsonConvert.SerializeObject(this.Data, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Serialize }); ``` But I can't do both. The signatures I get for SerializeObject are as follows. The 6th and 5th ones allow me to do the above respectively. I've looked into setting these settings globally but I haven't had much luck. Anyone know of a way to serialize using both of these settings?

Original source