-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix #3505 daterange default DateTime should not serialize #3546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a085358
Return overloads that do not take format on Field in 6.x, (#3543)
Mpdreamz 92ac7e7
try to reproduce #3538 to no avail
Mpdreamz 430df89
fix #3505 in the best way we can for 6.x
Mpdreamz 87a250b
default(DateTime) is actualy a conditionless condition
Mpdreamz 2f89229
added unit test for default(DateTime) conversion to DateMath
Mpdreamz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,95 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using Elastic.Xunit.XunitPlumbing; | ||
using FluentAssertions; | ||
using Nest; | ||
using Nest.JsonNetSerializer; | ||
using Newtonsoft.Json; | ||
using Tests.Core.Client.Settings; | ||
|
||
namespace Tests.Reproduce | ||
{ | ||
public class GithubIssue3538 | ||
{ | ||
[U] public void EmptyPolicyCausesNullReferenceException() | ||
{ | ||
var converter = new MyPocoJsonConverter(); | ||
var connectionSettings = new AlwaysInMemoryConnectionSettings( | ||
sourceSerializerFactory: (builtin, settings) => new JsonNetSerializer(builtin, settings, | ||
() => | ||
{ | ||
var jSettings = new JsonSerializerSettings(); | ||
jSettings.Converters.Add(converter); | ||
return jSettings; | ||
})) | ||
.DefaultIndex("blah"); | ||
|
||
var client = new ElasticClient(connectionSettings); | ||
|
||
var result = client.IndexDocument(new MyPoco() { Id = 1, Name = "x" }); | ||
converter.CanConvertCallCount.Should().Be(1); | ||
|
||
client.Bulk(b => b.Index<MyPoco>(i=>i.Document(new MyPoco { Id = 2, Name = "y" }))); | ||
converter.CanConvertCallCount.Should().Be(2); | ||
|
||
client.Bulk(b => b.Update<MyPoco>(i=>i.Doc(new MyPoco { Id = 3, Name = "z" }))); | ||
converter.CanConvertCallCount.Should().Be(3); | ||
|
||
client.Bulk(b => b.Update<MyPoco>(i=>i.Upsert(new MyPoco { Id = 4, Name = "a" }))); | ||
converter.CanConvertCallCount.Should().Be(4); | ||
|
||
converter.WriteCount.Should().Be(4); | ||
converter.SeenIds.Should().BeEquivalentTo(1, 2, 3, 4); | ||
|
||
} | ||
|
||
public class MyPoco | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
|
||
public class MyPocoJsonConverter : JsonConverter | ||
{ | ||
private int _canConvertCallCount; | ||
public int CanConvertCallCount => _canConvertCallCount; | ||
|
||
private int _writeCount; | ||
public int WriteCount => _writeCount; | ||
|
||
public List<int> SeenIds { get; } = new List<int>(); | ||
|
||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
Interlocked.Increment(ref _writeCount); | ||
|
||
if (!(value is MyPoco poco)) | ||
{ | ||
writer.WriteNull(); | ||
return; | ||
} | ||
|
||
writer.WriteStartObject(); | ||
writer.WritePropertyName("id"); | ||
writer.WriteValue(poco.Id); | ||
SeenIds.Add(poco.Id); | ||
writer.WritePropertyName("name"); | ||
writer.WriteValue(poco.Name); | ||
writer.WriteEndObject(); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) => | ||
new MyPoco { }; | ||
|
||
public override bool CanConvert(Type objectType) | ||
{ | ||
Interlocked.Increment(ref _canConvertCallCount); | ||
|
||
return objectType == typeof(MyPoco); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.