Client Library empty invariant nested field

I have…

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [x] Bug report
  • [ ] Performance issue
  • [ ] Documentation issue or request

Current behavior

When having an empty invariant nested field on a squidex, the api will return an empty object. When having the following attribute

[JsonConverter(typeof(InvariantConverter))]

the code will break on the check to see if it’s actually an IV field.

Example of the field in squidex

{
            "name": "colors",
            "properties": {
                "isRequired": false,
                "isRequiredOnPublish": false,
                "isHalfWidth": false,
                "fieldType": "Array",
                "minItems": 0,
                "maxItems": 3,
                "label": "Colors",
                "hints": "Themed Colours. Will alternate between"
            },
            "isLocked": false,
            "isHidden": false,
            "isDisabled": false,
            "partitioning": "invariant",
            "nested": [
                {
                    "name": "color",
                    "properties": {
                        "isRequired": true,
                        "isRequiredOnPublish": false,
                        "isHalfWidth": true,
                        "fieldType": "String",
                        "editor": "Dropdown",
                        "inlineEditable": false,
                        "isUnique": false,
                        "defaultValue": "Primary",
                        "allowedValues": [
                            "Primary",
                            "Secondary",
                            "Tertiary",
                            "Quaternary"
                        ],
                        "contentType": "Unspecified",
                        "label": "Color",
                        "hints": "The color of the card",
                        "placeholder": ""
                    },
                    "isLocked": false,
                    "isHidden": false,
                    "isDisabled": false
                }
            ]
        },

example response

{
    "id": "b78c3e87-498a-4aff-9cd9-4b3f88bd7b18",
    "createdBy": "...",
    "lastModifiedBy": "...",
    "data": {
        "fullWidth": {
            "iv": true
        },
        "centerText": {
            "iv": true
        },
        "colorGradient": {
            "iv": false
        },
        "colors": {},
        "title": {
            "nl": "..."
        },
        "description": {
            "nl": "..."
        },
        "cards": {
            "iv": [
                "552030..9f2",
                "77aa67..e4",
                "3b9520..ab"
            ]
        },
        "deletedDate": {
            "iv": null
        },
        "publishedDate": {
            "iv": "2021-03-30T13:02:46Z"
        }
    },
    "created": "2021-03-30T13:02:46Z",
    "lastModified": "2021-05-01T22:48:49Z",
    "status": "Published",
    "statusColor": "#4bb958",
    "schemaName": "cardsection",
    "schemaDisplayName": "Cards",
    "version": 3,
    "_links": {
        "self": {
            "href": "...",
            "method": "GET"
        },
        "previous": {
            "href": "...",
            "method": "GET"
        },
        "draft/create": {
            "href": "...",
            "method": "POST"
        },
        "delete": {
            "href": "...",
            "method": "DELETE"
        }
    }
}

As you can see the "colors": {}, is just an empty object.

Expected behavior

I think it would be beneficial if squidex would send the following object for invariant nested fields

{  
  ...
  "colors":{
     "iv" : []
  }
}

On first glimpse this would allow the ClientLibrary converter not fall over the empty object & insert an ‘empty’ collection into the correct field.

Alternatively an null could also be set, for a null value for the collection instead of an empty collection.

Minimal reproduction of the problem

  1. Create an scheme with an nested object like the one included
  2. Create content from said scheme, but don´t add any nested objects
  3. Create a C# model to work with the client library, and use the invariant converter
  4. Request the data

Environment

  • [ ] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [x] Cloud version

Browser:

  • [ ] Chrome (desktop)
  • [ ] Chrome (Android)
  • [ ] Chrome (iOS)
  • [x] Vivaldi (Chromium)
  • [ ] Firefox
  • [ ] Safari (desktop)
  • [ ] Safari (iOS)
  • [ ] IE
  • [ ] Edge

Hi,

this is a problem of the client library, I am not having plans to change this in Squidex. I will see, what I can do.

I’ve solved this by creating a new invariant converter, that creates an instance of the requested type if it’s assignable to an IEnumerable (To receive an empty collection)

I’m not sure if it’s the best use, or good ‘default’ behaviour but it solves my issues.

1 Like

I would extend the normal converter (PRs are welcome) to accept empty objects and then initialize your property with an empty list.

Hi, which version of the client library do you use?

There is this test: https://github.com/Squidex/squidex-samples/blob/master/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SerializationTests.cs#L190

Hey

Sorry for the late reply. I’m using 6.8.0. Perhaps I should update :slight_smile:

1 Like