Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Nest/Aggregations/Bucket/Composite/CompositeBucket.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Nest
{
Expand All @@ -25,6 +26,7 @@ public CompositeBucket(IReadOnlyDictionary<string, IAggregate> dict, CompositeKe
/// <summary>
/// A key for a <see cref="CompositeBucket" />
/// </summary>
[JsonConverter(typeof(VerbatimDictionaryKeysPreservingNullJsonConverter<string, object>))]
public class CompositeKey : IsAReadOnlyDictionaryBase<string, object>
{
private static readonly DateTimeOffset Epoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using Elastic.Xunit.XunitPlumbing;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Core.Client;
using Tests.Core.Extensions;

namespace Tests.Framework.SerializationTests
{
public class CompositeKeySerializationTests
{
[U] public void NullValuesAreSerialized()
{
var compositeKey = new CompositeKey(new Dictionary<string, object>
{
{ "key_1", "value_1" },
{ "key_2", null },
});

var serializer = TestClient.Default.RequestResponseSerializer;
var json = serializer.SerializeToString(compositeKey, SerializationFormatting.None);
json.Should().Be("{\"key_1\":\"value_1\",\"key_2\":null}");

using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
stream.Position = 0;
var dictionary = serializer.Deserialize<IReadOnlyDictionary<string, object>>(stream);
var deserializedCompositeKey = new CompositeKey(dictionary);
compositeKey.Should().Equal(deserializedCompositeKey);
}
}
}
}