C# Model with nested Component

I have the following data structure where the “kitContent” node is another component.

{
    "stockCode": {
        "iv": "RSK100"
    },
    "features": {
        "iv": []
    },
    "kitContent": {
        "iv": {
            "schemaId": "9e59bec4-d5ba-4cf2-9e09-c4e3e5ffadb1",
            "interchangeableWith": "92955807",
            "modelDescription": "ISUZU 4HE1 Various N Series (NPR70/ NPR71/ NQR70)",
            "interchangeableWith1": null,
            "modelDescription1": null,
            "contents": [
                {
                    "stockCode": "Z767",
                    "interchange": "8971482700",
                    "description": "Spin-on Oil Filter",
                    "quantity": 1
                },
                {
                    "stockCode": "Z784",
                    "interchange": "1132400791",
                    "description": "Spin-on Fuel Filter",
                    "quantity": 1
                }
            ]
        }
    },
    "fitmentGuides": {}
}

the equivalent C# model I am using as follows:

public class StockDetail : Content<StockDetailDto>
{
}

public class StockDetailDto
{
    [JsonConverter(typeof(InvariantConverter))]
    public string StockCode { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public List<FeatureDto> Feature { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public KitContent KitContent { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public List<FitmentGuidesDto> FitmentGuides { get; set; }

    public StockDetailDto()
    {
    }
}

public class KitContent : Content<KitContentDto>
{
    
}

public class KitContentDto
{
    [JsonConverter(typeof(InvariantConverter))]
    public string InterchangeableWith { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public string ModelDescription { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public string InterchangeableWith1 { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public string ModelDescription1 { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public List<ContentsDto> Contents { get; set; }

}

public class FeatureDto
{
    [JsonConverter(typeof(InvariantConverter))]
    public string Feature { get; set; }
}

public class ContentsDto
{
    [JsonConverter(typeof(InvariantConverter))]
    public string StockCode { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public string Interchange { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public string Description { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public double Quantity { get; set; }
}

public class FitmentGuidesDto
{
    [JsonConverter(typeof(InvariantConverter))]
    public string Title { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public string Url { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public string CantoId { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public string CantoDateModified { get; set; }
}

No matter how I try, not getting it right. Getting error or the KitContent has no data in it. Any direction is welcome.

FYI, I am trying this with the Squidex DotNet SDK.

Thanks,

It should be just

[JsonConverter(typeof(InvariantConverter))]
public KitContentDto KitContent { get; set; }
1 Like