From ec76835c95aa7c19204bda45693c720bf385700a Mon Sep 17 00:00:00 2001 From: Jeroen Breuer Date: Fri, 13 Sep 2024 14:13:05 +0200 Subject: [PATCH] Handle empty string fields in FieldConverter. (#12) ## Description This update addresses a specific issue encountered when dealing with JSON data for fields, such as the following example: ``` "fields": { "title": "", "leftLink": { "key": "40dfd6adb1334ff48c3e4c68ab9b9b35", "text": "The Energy Transition", "href": "/connections/energy-transition-and-sustainability/what-is-the-energy-transition" }, "rightLink": { "key": "de61e12028784b4da96a9676b73fc764", "text": "There are currently 54 known outages.", "href": "/outages-and-maintenance" } } ``` Previously, an empty string in the `title` field would trigger a `JsonException` in the `FieldConverter` because it was not recognized as a valid `JsonValueKind` type. This update introduces support for `JsonValueKind.String`, ensuring that empty strings are handled correctly alongside objects and arrays, thereby resolving the error. ## Motivation Custom Content Resolvers in both XM Cloud and Sitecore XP may return empty strings for certain fields, leading to errors in the `FieldConverter`. This enhancement ensures that such cases are handled properly, allowing for smooth operation regardless of whether an empty string is encountered. **Update:** Following the discussion below, this PR has been revised to focus on adding an integration test for fields with empty strings instead of altering the `FieldConverter`. --- tests/data/json/headlessSxa.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/data/json/headlessSxa.json b/tests/data/json/headlessSxa.json index 65da442..d820865 100644 --- a/tests/data/json/headlessSxa.json +++ b/tests/data/json/headlessSxa.json @@ -121,6 +121,29 @@ } ], "headless-main": [ + { + "uid": "a1d00efc-5354-4a58-9404-8448c532ad1d", + "componentName": "HeadlineBarSection", + "dataSource": "/sitecore/content/Test Collection/iva-test/Home/Data/HeadlineBar 1", + "params": { + "DynamicPlaceholderId": "2", + "FieldNames": "Banner", + "GridParameters": "col-12" + }, + "fields": { + "title": "", + "leftLink": { + "key": "40dfd6adb1334ff48c3e4c68ab9b9b35", + "text": "The Energy Transition", + "href": "/connections/energy-transition-and-sustainability/what-is-the-energy-transition" + }, + "rightLink": { + "key": "de61e12028784b4da96a9676b73fc764", + "text": "There are currently 54 known outages.", + "href": "/outages-and-maintenance" + } + } + }, { "uid": "86d9c1c9-1c1a-4886-af9f-526d8033df00", "componentName": "RichText",