Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using System.Dynamic;

namespace Synapse.Integration.Serialization.Converters
Expand All @@ -30,30 +29,16 @@ public class FilteredExpandoObjectConverter
: ExpandoObjectConverter
{

/// <summary>
/// Initializes a new <see cref="FilteredExpandoObjectConverter"/>
/// </summary>
/// <param name="namingStrategy">The <see cref="Newtonsoft.Json.Serialization.NamingStrategy"/> to use</param>
public FilteredExpandoObjectConverter(NamingStrategy namingStrategy = null)
{
this.NamingStrategy = namingStrategy ?? new CamelCaseNamingStrategy();
}

/// <inheritdoc/>
public override bool CanWrite => true;

/// <summary>
/// Gets the <see cref="Newtonsoft.Json.Serialization.NamingStrategy"/> to use
/// </summary>
protected NamingStrategy NamingStrategy { get; }

/// <inheritdoc/>
public override void WriteJson(JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
{
var expando = (IDictionary<string, object>)value;
var dictionary = expando
.Where(p => p.Value is not null)
.ToDictionary(p => this.NamingStrategy.GetPropertyName(p.Key, false), p => p.Value);
.ToDictionary(p => p.Key, p => p.Value);
serializer.Serialize(writer, dictionary);
}

Expand Down