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

Order of JSON in DataTypes inconsistent from default uSync behaviour #253

Open
AlexAtVista opened this issue Dec 9, 2024 · 1 comment
Open

Comments

@AlexAtVista
Copy link

AlexAtVista commented Dec 9, 2024

Describe the bug
Without uSync.Complete, the configuration for a block list is immediately serialized using JsonConvert.SerializeObject, with json settings using uSyncContractResolver to handle ordering the properties alphabetically. See line here

uSync.Complete appears to add a data type serializer for block lists that does not use these same json settings to order the properties, resulting in different file structures depending on if you have this installed or not.

This causes an issue for us as we programmatically generate these files for multiple projects, some using uSync.Complete and others not, causing half our projects to show changes due to the slightly difference in the structure of these files.

Version (please complete the following information):

  • Umbraco Version: 13.5.2
  • uSync Version: 13.2.5
  • uSync.Complete Version: 13.1.8

To Reproduce
Steps to reproduce the behavior:

  1. With only the uSync nuget package installed, create and/or save a block list data type.
  2. Observe the order of the Config property in the generated config file is alphabetical:
<?xml version="1.0" encoding="utf-8"?>
<DataType Key="21b4c2fa-6e23-5e22-a533-ba4e203eeb7b" Alias="FilmListDisplayTextLoader" Level="3">
<Info>
  <Name>FilmListDisplayTextLoader</Name>
  <EditorAlias>Umbraco.BlockList</EditorAlias>
  <DatabaseType>Ntext</DatabaseType>
  <Folder>Feature/FilmList</Folder>
</Info>
<Config><![CDATA[{
"Blocks": [
  {
    "backgroundColor": null,
    "contentElementTypeKey": "2f2f59f7-d449-5824-8131-fb0313066ae6",
    "editorSize": "medium",
    "forceHideContentEditorInOverlay": false,
    "iconColor": null,
    "label": "Film List Display Text",
    "settingsElementTypeKey": null,
    "stylesheet": null,
    "thumbnail": null,
    "view": null
  }
],
"MaxPropertyWidth": null,
"UseInlineEditingAsDefault": true,
"UseLiveEditing": false,
"UseSingleBlockMode": true,
"ValidationLimit": {
  "max": 1,
  "min": 1
}
}]]></Config>
</DataType>
  1. Install uSync.Complete, and re-save the block list data type
  2. Observe that the JSON is no longer alphabetical, instead ordered by the structure of the underlying model (In this case Umbraco.Cms.Core.PropertyEditors.BlockListConfiguration)
<?xml version="1.0" encoding="utf-8"?>
<DataType Key="21b4c2fa-6e23-5e22-a533-ba4e203eeb7b" Alias="FilmListDisplayTextLoader" Level="3">
  <Info>
    <Name>FilmListDisplayTextLoader</Name>
    <EditorAlias>Umbraco.BlockList</EditorAlias>
    <DatabaseType>Ntext</DatabaseType>
    <Folder>Feature/FilmList</Folder>
  </Info>
  <Config><![CDATA[{
  "Blocks": [
    {
      "backgroundColor": null,
      "iconColor": null,
      "thumbnail": null,
      "contentElementTypeKey": "2f2f59f7-d449-5824-8131-fb0313066ae6",
      "settingsElementTypeKey": null,
      "view": null,
      "stylesheet": null,
      "label": "Film List Display Text",
      "editorSize": "medium",
      "forceHideContentEditorInOverlay": false
    }
  ],
  "ValidationLimit": {
    "min": 1,
    "max": 1
  },
  "UseSingleBlockMode": true,
  "UseLiveEditing": false,
  "UseInlineEditingAsDefault": true,
  "MaxPropertyWidth": null
}]]></Config>
</DataType>

Expected behavior
The JSON should always be ordered alphabetically, per the 10.1 file format

@KevinJump
Copy link
Member

Hi, Thanks for reporting this.

I actually think its something just in the uSync core, which is inconsistent, installing uSync.Complete just shows it up 😟 .

turns out when you serialize a JObject it never hits. the contract resolver.

adding some code to the uSync.Core now that will sort JObject values inplace so when we serialize them, they are already sorted.

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

2 participants