Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Igor Besedin 1 post 71 karma points
    Jan 16, 2018 @ 09:21
    Igor Besedin
    0

    REST API throws exception on items with nested content

    I can't get content item through PublishedContentController of REST API if such item contains Umbraco.NestedContent property. Even if nested content type has no properties or has any number of any type properties. The only way when REST API works if property is null or empty array.

    I'm using empty Asp.NET web application, UmbracoCms 7.7.8, and UmbracoCms.RestApi 0.9.0.

    The exception in response:

    {
        "Message": "An error has occurred.",
        "ExceptionMessage": "The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.",
        "ExceptionType": "System.InvalidOperationException",
        "StackTrace": null,
        "InnerException": {
            "Message": "An error has occurred.",
            "ExceptionMessage": "Self referencing loop detected for property 'nestedProperty' with type 'System.Collections.Generic.List`1[Umbraco.Core.Models.IPublishedContent]'. Path 'properties.nestedProperty[0].contentSet[0]'.",
            "ExceptionType": "Newtonsoft.Json.JsonSerializationException",
            "StackTrace": "   в Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter writer, Object value, JsonProperty property, JsonContract contract, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n   ..."
        }
    }
    

    But when I'm requesting same data through ContentController, there are no errors and nested property returns correctly with json-serialized data. Example below:

    {
        "templateId": 0,
        "hasChildren": false,
        "sortOrder": 0,
        "contentTypeAlias": "hostType",
        "parentId": -1,
        "writerId": 0,
        "creatorId": 0,
        "path": "-1,1063",
        "level": 1,
        "id": 1063,
        "key": "cc0558a3-19d9-4970-811e-9fb722016b6d",
        "name": "host1",
        "createDate": "2018-01-16T10:35:29.4+00:00",
        "updateDate": "2018-01-16T11:24:29.887+00:00",
        "itemType": 0,
        "properties": {
            "nestedProperty": "[{\"key\":\"c78e66df-236f-421e-ab83-769bb7e1282d\",\"name\":\"Item 1\",\"ncContentTypeAlias\":\"nestedType\"},{\"key\":\"6f92ca74-ed5e-4565-9e9b-f7a9dfe574b1\",\"name\":\"Item 2\",\"ncContentTypeAlias\":\"nestedType\"},{\"key\":\"f58d0d7a-f98d-4a2c-87da-13ac705aa679\",\"name\":\"Item 3\",\"ncContentTypeAlias\":\"nestedType\"}]"
        },
        "_links": {
            ...
        }
    }
    

    I tested it on empty SqlCe database project.

    Does anyone knows why is this happening and how to make PublishedContentController work?

    Link to github

  • Thomas 319 posts 606 karma points c-trib
    Oct 19, 2020 @ 22:50
    Thomas
    0

    Did you find a solution for this ? :)

Please Sign in or register to post replies

Write your reply to:

Draft