-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for WKT with GeoLocation type (#4222)
Relates: elastic/elasticsearch#44107 This commit adds support for Well Known Text (WKT) representations for GeoLocation, the type used to represent geo_point in the client. Similar to WKT support in IGeoShape, an internal format field is used to store whether an instance was deserialized from JSON or WKT, so that re-serialization honours the original form deserialized from. (cherry picked from commit 3f3f98c)
- Loading branch information
Showing
5 changed files
with
123 additions
and
45 deletions.
There are no files selected for viewing
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
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
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
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
31 changes: 31 additions & 0 deletions
31
src/Tests/Tests/CodeStandards/Serialization/GeoLocationTests.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Text; | ||
using Elastic.Xunit.XunitPlumbing; | ||
using Elasticsearch.Net; | ||
using FluentAssertions; | ||
using Nest; | ||
using Tests.Core.Client; | ||
|
||
namespace Tests.CodeStandards.Serialization | ||
{ | ||
public class GeoLocationTests | ||
{ | ||
[U] | ||
public void CanDeserializeAndSerializeToWellKnownText() | ||
{ | ||
var wkt = "{\"location\":\"POINT (-90 90)\"}"; | ||
var client = TestClient.DisabledStreaming; | ||
|
||
Doc deserialized; | ||
using (var stream = MemoryStreamFactory.Default.Create(Encoding.UTF8.GetBytes(wkt))) | ||
deserialized = client.RequestResponseSerializer.Deserialize<Doc>(stream); | ||
|
||
deserialized.Location.Should().Be(new GeoLocation(90, -90)); | ||
client.RequestResponseSerializer.SerializeToString(deserialized).Should().Be(wkt); | ||
} | ||
|
||
private class Doc | ||
{ | ||
public GeoLocation Location { get; set; } | ||
} | ||
} | ||
} |