Skip to content

Commit 623c724

Browse files
russcamMpdreamz
authored andcommitted
Serialize GeoLocation with internal serializer (#3997)
This commit adds GeoLocation to types handled by the internal serializer so that a property on a document POCO of type GeoLocation is serialized by the internal serializer. It's not possible with the current test configuration to test this scenario, because IL rewriting happens after unit tests are run, so the Json.NET constructs used on Nest types are recognised by the JsonNetSerializer. Have added test that _would_ test behaviour, should tests be run after IL-merging in the future. Fixes #3981
1 parent 4a52b39 commit 623c724

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Serializers/Nest.JsonNetSerializer/Converters/HandleNestTypesOnSourceJsonConverter.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public class HandleNestTypesOnSourceJsonConverter : JsonConverter
1616
typeof(CompletionField),
1717
typeof(Attachment),
1818
typeof(ILazyDocument),
19-
typeof(GeoCoordinate)
19+
typeof(GeoCoordinate),
20+
typeof(GeoLocation)
2021
};
2122

2223
private readonly IElasticsearchSerializer _builtInSerializer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Text;
2+
using Elastic.Xunit.XunitPlumbing;
3+
using FluentAssertions;
4+
using Nest;
5+
using Tests.Core.Client;
6+
7+
namespace Tests.Reproduce
8+
{
9+
public class GitHubIssue3981
10+
{
11+
// This test always passes because the JsonPropertyAttribute on
12+
// the GeoLocation type are recognized by the JsonNetSerializer when used in tests, because the
13+
// IL rewriting to internalize Json.NET in the client happens *after* tests are run.
14+
[U]
15+
public void JsonNetSerializerSerializesGeoLocation()
16+
{
17+
var document = new Document
18+
{
19+
Location = new GeoLocation(45, 45)
20+
};
21+
22+
var indexResponse = TestClient.InMemoryWithJsonNetSerializer.IndexDocument(document);
23+
Encoding.UTF8.GetString(indexResponse.ApiCall.RequestBodyInBytes).Should().Contain("\"lat\"").And.Contain("\"lon\"");
24+
}
25+
26+
private class Document
27+
{
28+
public GeoLocation Location { get; set; }
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)