-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Documents previously indexed with TimeSpan as string cause UnexpectedElasticsearchClientException. #1809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
See #1809 In order to override the built in convention of serializing to long, a user would need to either register a converter for TimeSpan on ConnectionSettings or attribute TimeSpan properties
Hey @jonyadamit, This is a result of inferring I've made a change in ba0ea0a to be able to deserialize existing public class StringTimeSpanConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value == null)
writer.WriteNull();
else
{
var timeSpan = (TimeSpan)value;
writer.WriteValue(timeSpan.ToString());
}
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
if (!objectType.IsGeneric() || objectType.GetGenericTypeDefinition() != typeof(Nullable<>))
throw new JsonSerializationException($"Cannot convert null value to {objectType}.");
return null;
}
if (reader.TokenType == JsonToken.String)
{
return TimeSpan.Parse((string)reader.Value);
}
throw new JsonSerializationException($"Cannot convert token of type {reader.TokenType} to {objectType}.");
}
public override bool CanConvert(Type objectType) => objectType == typeof(TimeSpan) || objectType == typeof(TimeSpan?);
} |
@jonyadamit yes to adding to breaking changes; I'll add it now 👍 |
As a consequence of #1705 , types indexed prior to 2c3abf6 that have
TimeSpan/TimeSpan?
properties throw the following exception upon retrieval:The text was updated successfully, but these errors were encountered: