constructs JsonConverter instances in some scenarios that require state at the point of deserialization
handles not serializing empty collections or collections that only contain null items
gets property names from property mappings configured with NEST mapping attributes
builds serialization models for concrete types from implemented interfaces
You can however add your own JsonConverter instances, if you'd like to handle serialization for certain types in a particular way. Here's an example of defining our own converter for handling DateTime, DateTimeOffset and their nullable counterparts
void Main()
{
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings = new ConnectionSettings(
pool,
new HttpConnection(),
new SerializerFactory(settings => new CustomSerializer(settings)));
var client = new ElasticClient(connectionSettings);
}
public class CustomSerializer : JsonNetSerializer
{
public CustomSerializer(IConnectionSettingsValues settings) : base(settings)
{
}
protected override IList<Func<Type, JsonConverter>> ContractConverters =>
new List<Func<Type, JsonConverter>>
{
t => (t == typeof(DateTime) ||
t == typeof(DateTime?) ||
t == typeof(DateTimeOffset) ||
t == typeof(DateTimeOffset?))
? new Newtonsoft.Json.Converters.IsoDateTimeConverter { DateTimeStyles = System.Globalization.DateTimeStyles.AdjustToUniversal }
: null
};
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.