Skip to content

Commit

Permalink
(GH-476) Do not clone the Json serialization options to avoid problem…
Browse files Browse the repository at this point in the history
…s when library targets .net6 and is being used in a .net7 application

Resolves #476
  • Loading branch information
Jericho committed Nov 13, 2022
1 parent 0860042 commit 6910a38
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Source/StrongGrid/Json/BaseJsonConverter{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ internal void WriteJsonProperty(Utf8JsonWriter writer, string propertyName, obje

if (propertyConverterAttribute != null)
{
// It's important to clone the options in order to be able to modify the 'Converters' list
var clonedOptions = new JsonSerializerOptions(options);
clonedOptions.Converters.Add((JsonConverter)Activator.CreateInstance(propertyConverterAttribute.ConverterType));
JsonSerializer.Serialize(writer, propertyValue, propertyType, clonedOptions);
var customOptions = new JsonSerializerOptions()
{
Converters = { (JsonConverter)Activator.CreateInstance(propertyConverterAttribute.ConverterType) }
};
JsonSerializer.Serialize(writer, propertyValue, propertyType, customOptions);
}
else
{
Expand Down

0 comments on commit 6910a38

Please sign in to comment.