Last active
August 29, 2015 13:59
-
-
Save crunchie84/10536724 to your computer and use it in GitHub Desktop.
Different ways to add custom JsonConverters to ElasticSearch Nest (.net client)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var settings = new ConnectionSettings("http://localhost:9200) | |
.AddContractJsonConverters(type => | |
{ | |
//TypeCheck to return StringEnumConverter for Enums and Nullable<T> where T : Enum | |
if (type.IsEnum || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) && type.GetGenericArguments().First().IsEnum)) | |
return new Newtonsoft.Json.Converters.StringEnumConverter(); | |
return null; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var settings = new ConnectionSettings("http://localhost:9200) | |
.SetJsonSerializerSettingsModifier(jsonSerializerSettings => | |
{ | |
if (jsonSerializerSettings.Converters == null) | |
jsonSerializerSettings.Converters = new List<JsonConverter>(); | |
//by default will serialize all enum and nullable<T> where T : Enum to strings | |
jsonSerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
code examples for my blogpost @ http://markswanderingthoughts.nl/post/82479251894/configuring-custom-jsonconverters-in-nest-for-elasticsea