Skip to content

Commit 865f5fb

Browse files
committed
2 parents 1aa644e + ba0ea0a commit 865f5fb

File tree

9 files changed

+81
-19
lines changed

9 files changed

+81
-19
lines changed

src/Benchmarking/project.lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7811,7 +7811,7 @@
78117811
"runtime.win7.System.Net.Requests/4.0.11-beta-23516": {
78127812
"type": "package",
78137813
"serviceable": true,
7814-
"sha512": "mqWBQUhXhzkiwb+zVUuKg+wswJUsnQtZkFtz6eISw8vWNXA9i2jkzYjU3pjjIVmtdopnhle9YaS4a/w4OuWGLw==",
7814+
"sha512": "HI99nCEekL4SNvkLmpqkOE0PuEF5B6xyDcnJesdjo06BrGYH3QCvqJt2VmzBVe6hDSo6FnGOlhMvLdCUpDXiXA==",
78157815
"files": [
78167816
"ref/dotnet/_._",
78177817
"runtime.win7.System.Net.Requests.4.0.11-beta-23516.nupkg",

src/Elasticsearch.Net/project.lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,7 @@
17391739
"runtime.win7.System.Net.Requests/4.0.11-beta-23516": {
17401740
"type": "package",
17411741
"serviceable": true,
1742-
"sha512": "mqWBQUhXhzkiwb+zVUuKg+wswJUsnQtZkFtz6eISw8vWNXA9i2jkzYjU3pjjIVmtdopnhle9YaS4a/w4OuWGLw==",
1742+
"sha512": "HI99nCEekL4SNvkLmpqkOE0PuEF5B6xyDcnJesdjo06BrGYH3QCvqJt2VmzBVe6hDSo6FnGOlhMvLdCUpDXiXA==",
17431743
"files": [
17441744
"ref/dotnet/_._",
17451745
"runtime.win7.System.Net.Requests.4.0.11-beta-23516.nupkg",

src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/TimeSpanConverter.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Globalization;
3+
using System.Reflection;
24
using Newtonsoft.Json;
35

46
namespace Nest
@@ -25,14 +27,18 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
2527

2628
return null;
2729
}
30+
if (reader.TokenType == JsonToken.String)
31+
{
32+
return TimeSpan.Parse((string) reader.Value);
33+
}
34+
if (reader.TokenType == JsonToken.Integer)
35+
{
36+
return new TimeSpan((long) reader.Value);
37+
}
2838

29-
if (reader.TokenType != JsonToken.Integer)
30-
throw new JsonSerializationException($"Cannot convert token of type {reader.TokenType} to {objectType}.");
31-
32-
return new TimeSpan((long)reader.Value);
39+
throw new JsonSerializationException($"Cannot convert token of type {reader.TokenType} to {objectType}.");
3340
}
3441

35-
public override bool CanConvert(Type objectType) =>
36-
objectType == typeof (TimeSpan) || objectType == typeof (TimeSpan?);
42+
public override bool CanConvert(Type objectType) => objectType == typeof (TimeSpan) || objectType == typeof (TimeSpan?);
3743
}
3844
}

src/Nest/project.lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,7 @@
20592059
"runtime.win7.System.Net.Requests/4.0.11-beta-23516": {
20602060
"type": "package",
20612061
"serviceable": true,
2062-
"sha512": "mqWBQUhXhzkiwb+zVUuKg+wswJUsnQtZkFtz6eISw8vWNXA9i2jkzYjU3pjjIVmtdopnhle9YaS4a/w4OuWGLw==",
2062+
"sha512": "HI99nCEekL4SNvkLmpqkOE0PuEF5B6xyDcnJesdjo06BrGYH3QCvqJt2VmzBVe6hDSo6FnGOlhMvLdCUpDXiXA==",
20632063
"files": [
20642064
"ref/dotnet/_._",
20652065
"runtime.win7.System.Net.Requests.4.0.11-beta-23516.nupkg",

src/Tests/ClientConcepts/HighLevel/Mapping/AutoMap.doc.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ public class CompanyWithAttributes
295295
[String(Analyzer = "keyword", NullValue = "null", Similarity = SimilarityOption.BM25)]
296296
public string Name { get; set; }
297297

298+
[String]
299+
public TimeSpan? HeadOfficeHours { get; set; }
300+
298301
[Object(Path = "employees", Store = false)]
299302
public List<Employee> Employees { get; set; }
300303
}
@@ -383,6 +386,10 @@ public void UsingAutoMapWithAttributes()
383386
null_value = "null",
384387
similarity = "BM25",
385388
type = "string"
389+
},
390+
headOfficeHours = new
391+
{
392+
type = "string"
386393
}
387394
}
388395
},
@@ -531,6 +538,10 @@ public void OverridingAutoMappedAttributes()
531538
null_value = "null",
532539
similarity = "BM25",
533540
type = "string"
541+
},
542+
headOfficeHours = new
543+
{
544+
type = "string"
534545
}
535546
}
536547
},

src/Tests/Document/Single/Index/IndexApiTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public class IndexApiTests :
2222
Name = CallIsolatedValue,
2323
StartedOn = FixedDate,
2424
LastActivity = FixedDate,
25-
CuratedTags = new List<Tag> {new Tag {Name = "x", Added = FixedDate}}
25+
CuratedTags = new List<Tag> {new Tag {Name = "x", Added = FixedDate}},
26+
2627
};
2728

2829
public IndexApiTests(IndexingCluster cluster, EndpointUsage usage) : base(cluster, usage)
@@ -111,17 +112,17 @@ public void OpTypeCreate()
111112
public void Index()
112113
{
113114
var indexName = this.RandomString();
114-
var project = Project.Generator.Generate(1).First();
115-
var indexResult = this.Client.Index(project, f => f.Index(indexName));
115+
var commitActivity = CommitActivity.Generator.Generate(1).First();
116+
var indexResult = this.Client.Index(commitActivity, f => f.Index(indexName));
116117
indexResult.IsValid.Should().BeTrue();
117118
indexResult.ApiCall.HttpStatusCode.Should().Be(201);
118119
indexResult.Created.Should().BeTrue();
119120
indexResult.Index.Should().Be(indexName);
120-
indexResult.Type.Should().Be(this.Client.Infer.TypeName<Project>());
121-
indexResult.Id.Should().Be(project.Name);
121+
indexResult.Type.Should().Be(this.Client.Infer.TypeName<CommitActivity>());
122+
indexResult.Id.Should().Be(commitActivity.Id);
122123
indexResult.Version.Should().Be(1);
123124

124-
indexResult = this.Client.Index(project, f => f.Index(indexName));
125+
indexResult = this.Client.Index(commitActivity, f => f.Index(indexName));
125126

126127
indexResult.IsValid.Should().BeTrue();
127128
indexResult.Created.Should().BeFalse();

src/Tests/Framework/MockData/CommitActivity.cs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
22
using Bogus;
3+
using Nest;
4+
using Newtonsoft.Json;
5+
using Newtonsoft.Json.Serialization;
36

47
namespace Tests.Framework.MockData
58
{
@@ -13,6 +16,14 @@ public class CommitActivity
1316
public Developer Committer { get; set; }
1417
public TimeSpan? Duration { get; set; }
1518

19+
[String]
20+
[JsonConverter(typeof(StringTimeSpanConverter))]
21+
public TimeSpan? StringDuration
22+
{
23+
get { return Duration; }
24+
set { Duration = value; }
25+
}
26+
1627
public static Faker<CommitActivity> Generator { get; } =
1728
new Faker<CommitActivity>()
1829
.RuleFor(p => p.Id, p => Guid.NewGuid().ToString("N").Substring(0, 8))
@@ -25,12 +36,45 @@ public class CommitActivity
2536
{
2637
TimeSpan.MinValue,
2738
TimeSpan.MaxValue,
28-
null,
29-
TimeSpan.Zero,
3039
TimeSpan.FromMinutes(7.5),
40+
TimeSpan.Zero,
41+
null,
3142
TimeSpan.FromHours(4.23),
3243
TimeSpan.FromDays(5),
3344
}))
3445
;
3546
}
47+
48+
internal class StringTimeSpanConverter : JsonConverter
49+
{
50+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
51+
{
52+
if (value == null)
53+
writer.WriteNull();
54+
else
55+
{
56+
var timeSpan = (TimeSpan)value;
57+
writer.WriteValue(timeSpan.ToString());
58+
}
59+
}
60+
61+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
62+
{
63+
if (reader.TokenType == JsonToken.Null)
64+
{
65+
if (!objectType.IsGeneric() || objectType.GetGenericTypeDefinition() != typeof(Nullable<>))
66+
throw new JsonSerializationException($"Cannot convert null value to {objectType}.");
67+
68+
return null;
69+
}
70+
if (reader.TokenType == JsonToken.String)
71+
{
72+
return TimeSpan.Parse((string)reader.Value);
73+
}
74+
75+
throw new JsonSerializationException($"Cannot convert token of type {reader.TokenType} to {objectType}.");
76+
}
77+
78+
public override bool CanConvert(Type objectType) => objectType == typeof(TimeSpan) || objectType == typeof(TimeSpan?);
79+
}
3680
}

src/Tests/project.lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6406,7 +6406,7 @@
64066406
"runtime.win7.System.Net.Requests/4.0.11-beta-23516": {
64076407
"type": "package",
64086408
"serviceable": true,
6409-
"sha512": "mqWBQUhXhzkiwb+zVUuKg+wswJUsnQtZkFtz6eISw8vWNXA9i2jkzYjU3pjjIVmtdopnhle9YaS4a/w4OuWGLw==",
6409+
"sha512": "HI99nCEekL4SNvkLmpqkOE0PuEF5B6xyDcnJesdjo06BrGYH3QCvqJt2VmzBVe6hDSo6FnGOlhMvLdCUpDXiXA==",
64106410
"files": [
64116411
"ref/dotnet/_._",
64126412
"runtime.win7.System.Net.Requests.4.0.11-beta-23516.nupkg",

src/Tests/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mode either u (unit test), i (integration test) or m (mixed mode)
2-
mode: i
2+
mode: m
33
# the elasticsearch version that should be started
44
elasticsearch_version: 2.0.1
55
# whether we want to forcefully reseed on the node, if you are starting the tests with a node already running

0 commit comments

Comments
 (0)