Impedir $ id / $ ref ao serializar objetos usando a API da Web e JSON.NET
Não consigo impedir a API / JSON.NET da Web de usarNewtonsoft.Json.PreserveReferencesHandling.Objects
ao serializar objetos. Em outras palavras, $ id / $ ref são sempre usados nos objetos serializados, apesar de usar as seguintes configurações:
public class MvcApplication : System.Web.HttpApplication {
protected void Application_Start () {
WebApiConfig.Register(GlobalConfiguration.Configuration);
}
}
public static class WebApiConfig {
public static void Register (HttpConfiguration config) {
JsonMediaTypeFormatter jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().Single();
jsonFormatter.UseDataContractJsonSerializer = false;
jsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
jsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
jsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
}
}
Alguma ideia?