Skip to content

Commit

Permalink
Fix dictionary key serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Dec 7, 2023
1 parent 72b0161 commit c87a616
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion csharp/Squidex.ClientLibrary/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageTags>Squidex HeadlessCMS</PackageTags>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>17.1.0</Version>
<Version>17.2.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,20 @@ public void Should_deserialize_localized_jsonnull()

Assert.Equal("hello", result?.Value["en"].Value);
}

[Fact]
public void Should_keep_dictionary_keys()
{
var workflow = new UpdateWorkflowDto
{
Steps = new Dictionary<string, WorkflowStepDto>
{
["Draft"] = new WorkflowStepDto()
}
};

var result = workflow.ToJson(options);

Assert.Contains("Draft", result, StringComparison.Ordinal);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Squidex.ClientLibrary.Configuration;
using Squidex.ClientLibrary.Utils;

Expand Down Expand Up @@ -35,7 +36,13 @@ public class SquidexOptions : OptionsBase
/// </summary>
public SquidexOptions()
{
SerializerSettings.ContractResolver = new JsonNullContractResolver();
SerializerSettings.ContractResolver = new JsonNullContractResolver()
{
NamingStrategy = new CamelCaseNamingStrategy
{
OverrideSpecifiedNames = true
}
};

SerializerSettings.Converters.Add(new StringEnumConverter());
SerializerSettings.Converters.Add(new UTCIsoDateTimeConverter());
Expand Down

0 comments on commit c87a616

Please sign in to comment.