diff --git a/src/Serializers/Nest.JsonNetSerializer/Converters/HandleNestTypesOnSourceJsonConverter.cs b/src/Serializers/Nest.JsonNetSerializer/Converters/HandleNestTypesOnSourceJsonConverter.cs index 0c2db7c32da..67b5b0e04eb 100644 --- a/src/Serializers/Nest.JsonNetSerializer/Converters/HandleNestTypesOnSourceJsonConverter.cs +++ b/src/Serializers/Nest.JsonNetSerializer/Converters/HandleNestTypesOnSourceJsonConverter.cs @@ -45,7 +45,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist //even though we pass type JSON.NET won't try the registered converter for that type //even if it can handle string tokens :( if (objectType == typeof(JoinField) && token.Type == JTokenType.String) - return JoinField.Root(token.ToString(Formatting.None)); + return JoinField.Root(token.Value()); using (var ms = token.ToStream()) return _builtInSerializer.Deserialize(objectType, ms); diff --git a/src/Tests/Tests.Core/Client/TestClient.cs b/src/Tests/Tests.Core/Client/TestClient.cs index c5e53880c36..3c7729113e9 100644 --- a/src/Tests/Tests.Core/Client/TestClient.cs +++ b/src/Tests/Tests.Core/Client/TestClient.cs @@ -1,4 +1,5 @@ using Nest; +using Nest.JsonNetSerializer; using Tests.Configuration; using Tests.Core.Client.Settings; using Tests.Domain.Extensions; @@ -9,6 +10,8 @@ public static class TestClient { public static readonly IElasticClient Default = new ElasticClient(new TestConnectionSettings().ApplyDomainSettings()); public static readonly IElasticClient DefaultInMemoryClient = new ElasticClient(new AlwaysInMemoryConnectionSettings().ApplyDomainSettings()); + public static readonly IElasticClient InMemoryWithJsonNetSerializer = new ElasticClient( + new AlwaysInMemoryConnectionSettings(sourceSerializerFactory: JsonNetSerializer.Default).ApplyDomainSettings()); public static readonly IElasticClient DisabledStreaming = new ElasticClient(new TestConnectionSettings().ApplyDomainSettings().DisableDirectStreaming()); public static readonly ITestConfiguration Configuration = TestConfiguration.Instance; diff --git a/src/Tests/Tests.Core/Serialization/SerializationTester.cs b/src/Tests/Tests.Core/Serialization/SerializationTester.cs index 84e58438dc3..d5acbad7bf6 100644 --- a/src/Tests/Tests.Core/Serialization/SerializationTester.cs +++ b/src/Tests/Tests.Core/Serialization/SerializationTester.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Text; using Elasticsearch.Net; using FluentAssertions; @@ -64,6 +65,8 @@ public class SerializationTester { public static SerializationTester Default { get; } = new SerializationTester(TestClient.DefaultInMemoryClient); + public static SerializationTester DefaultWithJsonNetSerializer { get; } = new SerializationTester(TestClient.InMemoryWithJsonNetSerializer); + public SerializationTester(IElasticClient client) => this.Client = client; public IElasticClient Client { get; } diff --git a/src/Tests/Tests.Reproduce/GithubIssue3356.cs b/src/Tests/Tests.Reproduce/GithubIssue3356.cs new file mode 100644 index 00000000000..0642299a64c --- /dev/null +++ b/src/Tests/Tests.Reproduce/GithubIssue3356.cs @@ -0,0 +1,36 @@ +using System; +using Elastic.Xunit.XunitPlumbing; +using FluentAssertions; +using Nest; +using Tests.Core.Extensions; +using Tests.Core.Serialization; + +namespace Tests.Reproduce +{ + public class GithubIssue3356 + { + [U] + public void JoinFieldDeserializedCorrectly() + { + var doc = new MyDocument + { + Join = JoinField.Root("parent") + }; + + var tester = SerializationTester.DefaultWithJsonNetSerializer; + var response = tester.Client.IndexDocument(doc); + + tester.AssertSerialize(response.ApiCall.RequestBodyInBytes, new { join = "parent" }); + doc = tester.AssertDeserialize(response.ApiCall.RequestBodyInBytes); + + doc.Join.Match( + p => { p.Name.Should().Be("parent"); }, + c => throw new InvalidOperationException("should not be called")); + } + + private class MyDocument + { + public JoinField Join { get; set; } + } + } +}