Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON deserialize exception when importing migrated Blocklist data over legacy Nested Content #632

Open
BarryFogarty opened this issue Apr 24, 2024 · 5 comments

Comments

@BarryFogarty
Copy link

I am migrating legacy v8 Nested Content to BlockList v13. Datatypes import fine, however the following error is generated when importing content:

Error: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Umbraco.Cms.Core.Models.Blocks.BlockValue' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. Path '', line 1, position 1.

Interestingly this only seems to affect unpublished content items. It seems to be a reasonably recent regression as importing the same files to a v12.3.9 (with uSync 12.2.3) is not affected.

NB I am importing on top of an existing database, in order to maintain user permission config. I will try on a fresh DB but I believe it is not affected by this issue. Perhaps uSync is first attempting to deserialize the Nested Content data held in the blocklist property in this context, rather than simply overwriting it.

@KevinJump
Copy link
Owner

Hi,

Have you used uSync.Migrations to Generate the migrated files ? or have you done that another way.

@BarryFogarty
Copy link
Author

BarryFogarty commented Apr 24, 2024

Hi Kevin - yes I generated a sync pack on the v8 site with a Packer. Then used uSync.Migrations on the v13 target site to generate the files. The migration part works fine, the failure happens on an in-place import. It is something to do with the unpublished state. The error does not occur when I edit a generated file to <Published Default="true" />

@KevinJump
Copy link
Owner

hi if you can send us the file i'll see if i can spot anything ([email protected]).

@psmoq
Copy link

psmoq commented Apr 29, 2024

I can confirm above behavior. Generated config files (uSync.Migrations) contain properly migrated values (blocklists instead of nested content in my case). However it fails during the import (same exception as above). Downgrade to v12 fixes the problem.

@mistyn8
Copy link
Contributor

mistyn8 commented Jul 26, 2024

Getting this too.. The migrated config is below..
If it helps.. it does seem to relate to unpublished content.

Some more info.. If I try to set the link and save the content node in the backoffice I get failed to save prob due to bad import data.. However, if I then publish and unpublish with a new link.. then rerunning the import it all works?

In between I did add to the MultipleUrlPickerMigrator which was the bad data in my instance..

using uSync.Migrations.Migrators.Core;
using UmbConstants = Umbraco.Cms.Core.Constants;

namespace uSyncMigrationSite.Extensions.Migrators
{

    [SyncMigrator(UmbConstants.PropertyEditors.Aliases.MultiUrlPicker)]
    [SyncMigratorVersion(8)]
    public class SMMultiUrlPickerMigrator : MultiUrlPickerMigrator
    {
        public override string? GetContentValue(SyncMigrationContentProperty contentProperty, SyncMigrationContext context)
        {
            if (string.IsNullOrWhiteSpace(contentProperty.Value))
            {
                return contentProperty.Value;
            }

            try
            {
                var config = JsonConvert.DeserializeObject<List<MultiUrlPickerValueEditor.LinkDto>>(contentProperty.Value);
                return JsonConvert.SerializeObject(config);
            }
            catch
            {
                var x = base.GetContentValue(contentProperty, context);
                return x;
            }
        }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<Content Key="807c1ba9-4b87-43cd-8982-e2a0f192a68a" Alias="Merry Christmas" Level="4">
  <Info>
    <Parent Key="28eea678-91b8-4f00-9482-ecd52e8b0339">Homepage Auctions</Parent>
    <Path>/Assets/Carousels/HomepageAuctions/MerryChristmas</Path>
    <Trashed>false</Trashed>
    <ContentType>carouselSlide</ContentType>
    <CreateDate>2021-12-14T18:42:16</CreateDate>
    <NodeName Default="Merry Christmas" />
    <SortOrder>21</SortOrder>
    <Published Default="false" />
    <Schedule />
    <Template />
  </Info>
  <Properties>
    <backgoundImage>
      <Value><![CDATA[[
  {
    "key": "cf33277c-b7fe-412e-b0db-d125066e5f06",
    "mediaKey": "15d2a64b-31f4-443c-a2cd-bc8a4c4fe1b4"
  }
]]]></Value>
    </backgoundImage>
    <cta>
      <Value><![CDATA[{
  "layout": {
    "Umbraco.BlockList": [
      {
        "contentUdi": "umb://element/46ba635a626c48dd8c9d03cad844d672"
      }
    ]
  },
  "contentData": [
    {
      "contentTypeKey": "a8dc72bc-1c2c-4e80-ab60-b99c91b1cf17",
      "udi": "umb://element/46ba635a626c48dd8c9d03cad844d672",
      "link": "[{\"name\":\".\",\"target\":null,\"udi\":\"umb://document/4b5454af0fe24529997231be8df1cae9\",\"url\":null,\"queryString\":null}]",
      "buttonColour": "{\r\n  \"value\": \"ffffff\",\r\n  \"label\": \"White\",\r\n  \"sortOrder\": 1,\r\n  \"id\": \"2\"\r\n}",
      "backgroundColour": ""
    }
  ],
  "settingsData": []
}]]></Value>
    </cta>
    <description>
      <Value><![CDATA[<p> </p>
<p><span class="ui-provider">Thank you for your support in 2023 and we hope you have a successful 2024. We wish you an enjoyable and safe Christmas, with family and loved ones.</span></p>
<p>Our offices and auction centres will be closed from 1pm on Friday 22nd December and will re-open on Tuesday 2nd January.</p>
<p>Have a great Christmas and a happy New Year!</p>]]></Value>
    </description>
    <saleId>
      <Value><![CDATA[]]></Value>
    </saleId>
    <subtitle>
      <Value><![CDATA[& Happy New Year]]></Value>
    </subtitle>
  </Properties>
</Content>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants