I have a content schema with root element "labelSet" and a single multi-value embeddable schema field with xml name "labels".
The embeddable schema field has a root element "label" and has 2 text fields with xml names "key" and "value" respectively.
I am requesting a DCP (dynamic component presentation) and receive a populated IComponent fully populated with the embedded values but I want to de-serialize this into a strongly typed model using the IViewModelFactory
.
LabelSet.cs:
[ContentModel("labelSet", true)]
public class LabelSet : ViewModelBase
{
[EmbeddedSchemaField(FieldName = "labels", EmbeddedModelType = typeof(Label))]
public List<Label> Labels { get; set; }
}
Label.cs:
[ContentModel("label", true)]
public class Label : ViewModelBase
{
[TextField(FieldName = "key")]
public string Key { get; set; }
[TextField(FieldName = "value")]
public string Value { get; set; }
}
When I call...
// component is a fully populated IComponent instance
var model = viewModelFactory.BuildViewModel<LabelSet>(component);
...I get an instance of my LabelSet
class but the Labels property is null.
Here is a JSON serialized instance of the IComponent I am trying to serialize:
{
"LastPublishedDate": "0001-01-01T00:00:00",
"RevisionDate": "2017-01-26T20:55:17",
"Schema": {
"Folder": {
"PublicationId": "tcm:0-7-1",
"Publication": null,
"OwningPublication": null,
"Id": "tcm:7-16-2",
"Title": "Content",
"ExtensionData": null
},
"RootElementName": "labelSet",
"PublicationId": null,
"Publication": {
"Id": "tcm:0-7-1",
"Title": "050 Common Website",
"ExtensionData": null
},
"OwningPublication": null,
"Id": "tcm:7-77-8",
"Title": "LabelSet",
"ExtensionData": null
},
"Fields": {
"labels": {
"Name": "labels",
"Values": [
],
"NumericValues": [
],
"DateTimeValues": [
],
"LinkedComponentValues": [
],
"EmbeddedValues": [
{
"key": {
"Name": "key",
"Values": [
"ApplicationTitle"
],
"NumericValues": [
],
"DateTimeValues": [
],
"LinkedComponentValues": [
],
"EmbeddedValues": null,
"EmbeddedSchema": null,
"FieldType": 0,
"CategoryName": null,
"CategoryId": null,
"XPath": "tcm:Content/custom:labelSet/custom:labels[1]/custom:key",
"KeywordValues": [
]
},
"value": {
"Name": "value",
"Values": [
"DD4T Training"
],
"NumericValues": [
],
"DateTimeValues": [
],
"LinkedComponentValues": [
],
"EmbeddedValues": null,
"EmbeddedSchema": null,
"FieldType": 0,
"CategoryName": null,
"CategoryId": null,
"XPath": "tcm:Content/custom:labelSet/custom:labels[1]/custom:value",
"KeywordValues": [
]
}
}
],
"EmbeddedSchema": {
"Folder": {
"PublicationId": "tcm:0-7-1",
"Publication": null,
"OwningPublication": null,
"Id": "tcm:7-17-2",
"Title": "Embeddable",
"ExtensionData": null
},
"RootElementName": "label",
"PublicationId": null,
"Publication": {
"Id": "tcm:0-7-1",
"Title": "050 Common Website",
"ExtensionData": null
},
"OwningPublication": null,
"Id": "tcm:7-76-8",
"Title": "Label",
"ExtensionData": null
},
"FieldType": 4,
"CategoryName": null,
"CategoryId": null,
"XPath": "tcm:Content/custom:labelSet/custom:labels",
"KeywordValues": [
]
}
},
"MetadataFields": {
},
"ComponentType": 1,
"Multimedia": null,
"Folder": {
"PublicationId": "tcm:0-7-1",
"Publication": null,
"OwningPublication": null,
"Id": "tcm:7-21-2",
"Title": "LabelSets",
"ExtensionData": null
},
"Categories": [
],
"Version": 3,
"EclId": null,
"PublicationId": null,
"Publication": {
"Id": "tcm:0-7-1",
"Title": "050 Common Website",
"ExtensionData": null
},
"OwningPublication": {
"Id": "tcm:0-4-1",
"Title": "030 Common Content",
"ExtensionData": null
},
"Id": "tcm:7-79",
"Title": "General",
"ExtensionData": null
}