Serialization error with Elasticsearch NEST/C#

故事扮演 提交于 2019-12-24 03:08:40

问题


I'm using NEST to index my objects and I'm running into a Newtonsoft error on serialization. One of my objects has a self referencing loop. Would there be a way for me to access the JsonSerializer and change how it handles self-references without having to modify the source code?


回答1:


You can register custom converters on your client:

public void AddConverter(JsonConverter converter)
{
    this.IndexSerializationSettings.Converters.Add(converter);
    this.SerializationSettings.Converters.Add(converter);
}

This might be of help.

There is no direct way to alter the JsonSerializerSettings used in the client though.




回答2:


There is a new api now, take a look at:

    var cs2 = new ConnectionSettings(new Uri("http://localhost:9200"))
        .SetJsonSerializerSettingsModifier(settings => settings.TypeNameHandling = TypeNameHandling.None)
        .EnableTrace();

Thanks for adding the support!



来源:https://stackoverflow.com/questions/14593378/serialization-error-with-elasticsearch-nest-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!