Skip to content

Commit 6181ba1

Browse files
authored
Merge pull request #102 from Kentico/fix/reference-null-values
Fix serializing null value in reference custom data fields
2 parents 08eff42 + 9f4cebf commit 6181ba1

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/Kentico.Xperience.UMT/Services/ContentItemReferencePopulator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using CMS.ContentEngine.Internal;
1+
using System.Text.Json;
2+
23
using CMS.ContentEngine;
4+
using CMS.ContentEngine.Internal;
35
using CMS.DataEngine;
46
using CMS.FormEngine;
57

68
using Kentico.Xperience.UMT.Utils;
79

8-
using System.Text.Json;
9-
1010
namespace Kentico.Xperience.UMT.Services
1111
{
1212
internal class ContentItemReferencePopulator
@@ -24,7 +24,7 @@ internal static void Preprocess(
2424
.Select(field => (FieldName: field.Name, Value: customData[field.Name]))
2525
.Where(x => x.Value is not string))
2626
{
27-
customData[fieldName] = JsonSerializer.Serialize(value);
27+
customData[fieldName] = value is not null ? JsonSerializer.Serialize(value, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) : null;
2828
}
2929
}
3030

@@ -77,7 +77,7 @@ ContentItemCommonDataInfo commonDataInfo
7777
{
7878
if (contentItemReferenceFieldValue is string serializedValue)
7979
{
80-
var value = JsonSerializer.Deserialize<IEnumerable<ContentItemReference>>(serializedValue);
80+
var value = JsonSerializer.Deserialize<IEnumerable<ContentItemReference>?>(serializedValue, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
8181
if (value is not null)
8282
{
8383
foreach (var targetItemGuid in value.Select(x => x.Identifier))

0 commit comments

Comments
 (0)