I am currently facing a challenge with deserializing a JSON object returned from Umbraco CMS that contains dynamic fields.
The json object returned from Umbraco is highly customizable which may have examples like this.
{
"content": {
"DataType": null,
"header": {
"title": "",
"logo": null,
"navigation": []
},
"footer": {
"Name" : "this is the footer"
"logo": null,
"Links": 0.0,
"copyRight": ""
}
}
or something more complicated like
{
"overview": "<h2>Content Overview</h2><p><a href=\"https://\">Text</a></p>",
"isVisible": false,
"description": "describe your product",
"bulletItems": [
"settings": null,
"content":{
"item": "confidential service",
"contentType": {
"key": "123",
"id": 1111,
"alias": "item",
"itemType": "Element",
"properties": [
{
"referenceCacheLevel": "Element",
"propertyType": {
"contentType": {
"key": "3234234",
"id": 1112,
"alias": "bulletItem",
"itemType": "Element",
"compositionAliases": [],
"variations": "Nothing",
"propertyTypes": [],
"isElement": true
}
}
}
]
}
}
]
}
Specifically, the received object may or may not include fields such as header, footer, icon, link, title, content, and so on. My goal is to deserialize this object and fit it into a standard structure (the structure covers the fields, arrays with objects which we are required). If it has the property in my class (same name), then deserialize it and fill in the fields. If it does not have the related properties, then leave it empty. In essence, the imported JSON object will serve as a data source, and the desired outcome will be an object that adheres to the standardized structure with all the necessary elements filtered accordingly.
For instance, here is the structure I have defined:
public class MyContentClass
{
public Header header;
public Footer footer;
public string title;
...
}
public class Header
{
public string name;
public int height;
public List<property> properties;
...
}
public class Footer
{
public string name;
public string content1;
public string content2;
public List<property> properties;
...
}
...
Any advice/suggestion will be highly appreciated.