I have just upgraded to v17 from v13 and some code that I had written for a custom search indexer (for Azure search) now does not work for documents with block lists because it cannot deserialize the string value to json.
This code gets data for any block list fields (in this example, just one field):
var rawComponents = new List<BlockValue>()
{
GetBlockValue(content.GetValue<string>("components"))
}.Where(x => x != null).SelectMany(x => x.ContentData);
The GetBlockValue function is as follows, it deserializes it from the string value into the BlockValue object:
BlockValue GetBlockValue(string json)
{
return string.IsNullOrWhiteSpace(json) ? null : Newtonsoft.Json.JsonConvert.DeserializeObject<BlockValue>(json);
}
This now throws the following error:
Could not create an instance of type Umbraco.Cms.Core.Models.Blocks.BlockValue. Type is an interface or abstract class and cannot be instantiated. Path 'contentData', line 1, position 15.
If I create my own class to sit on top of BlockValue, I get this error:
Could not create an instance of type Umbraco.Cms.Core.Models.Blocks.IBlockLayoutItem. Type is an interface or abstract class and cannot be instantiated. Path 'Layout['Umbraco.BlockList'][0].contentUdi', line 1, position 581.
Here’s the value from one of the blocklist fields:
{
"contentData": [
{
"contentTypeKey": "74a0b202-b95c-43f6-82ea-5df1b515b2ed",
"udi": null,
"key": "6c5220d4-aa75-46a3-ae23-a0c75f9546b3",
"values": [
{
"editorAlias": "Umbraco.RichText",
"culture": null,
"segment": null,
"alias": "content",
"value": "{\\u0022markup\\u0022:\\u0022\\\\u003Cp\\\\u003Erte\\\\u003C/p\\\\u003E\\u0022,\\u0022blocks\\u0022:{\\u0022contentData\\u0022:[],\\u0022settingsData\\u0022:[],\\u0022expose\\u0022:[],\\u0022Layout\\u0022:{}}}"
}
]
}
],
"settingsData": [],
"expose": [
{
"contentKey": "6c5220d4-aa75-46a3-ae23-a0c75f9546b3",
"culture": null,
"segment": null
}
],
"Layout": {
"Umbraco.BlockList": [
{
"contentUdi": null,
"settingsUdi": null,
"contentKey": "6c5220d4-aa75-46a3-ae23-a0c75f9546b3",
"settingsKey": null
}
]
}
}
I’m at a bit of a loss as I have been unable to find any documentation around this change, some help would be great!