Skip to content

Commit 978d2f3

Browse files
committed
Use DateParseHandling.None when loading JObject for MultiGetHit<T> (#3611)
Fixes #3554
1 parent 1051a57 commit 978d2f3

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/Nest/Document/Multiple/MultiGet/Response/MultiGetHitJsonConverter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
4646
}
4747

4848
var response = new MultiGetResponse();
49+
50+
var dateParseHandling = reader.DateParseHandling;
51+
reader.DateParseHandling = DateParseHandling.None;
4952
var jsonObject = JObject.Load(reader);
53+
reader.DateParseHandling = dateParseHandling;
54+
5055
var docsJarray = (JArray)jsonObject["docs"];
5156
if (_request == null || docsJarray == null)
5257
return response;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Linq;
2+
using Elastic.Xunit.XunitPlumbing;
3+
using FluentAssertions;
4+
using Nest;
5+
using Tests.Core.Extensions;
6+
using Tests.Core.ManagedElasticsearch.Clusters;
7+
8+
namespace Tests.Reproduce
9+
{
10+
public class GithubIssue3554 : IClusterFixture<WritableCluster>
11+
{
12+
private readonly WritableCluster _cluster;
13+
14+
public GithubIssue3554(WritableCluster cluster) => _cluster = cluster;
15+
16+
[I] public void GetManyDoesNotDeserializeDateTimeLikeStringsToDateTime()
17+
{
18+
var doc = new CreatedAtDocument { CreatedAt = "2009-11-15T14:12:12" };
19+
var client = _cluster.Client;
20+
var createIndexResponse = client.CreateIndex("githubissue3554", c => c
21+
.Mappings(m => m
22+
.Map<CreatedAtDocument>(mm => mm
23+
.Properties(p => p
24+
.Keyword(k => k
25+
.Name(n => n.CreatedAt)
26+
)
27+
)
28+
)
29+
)
30+
);
31+
32+
createIndexResponse.ShouldBeValid();
33+
var indexResponse = client.Index(doc, i => i.Id(1));
34+
indexResponse.ShouldBeValid();
35+
36+
var getManyResponse = client.GetMany<CreatedAtDocument>(new long[] { 1 });
37+
getManyResponse.First().Source.CreatedAt.Should().Be(doc.CreatedAt);
38+
}
39+
40+
public class CreatedAtDocument
41+
{
42+
public string CreatedAt { get; set; }
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)