I'm implementing DD4T 2 Java version.
When a component have only one keyword value in it's field, DD4T gets 4 same keyword values. For instance, a component has only one keyword, which is "Keyword", DD4T gets 4 "Keyword" values as if same keyword is specified in one field 4 times.
It seems a problem of DD4T default templates. When previewing a page on CME, rendered JSON include multiple keywords.
Result of page preview is follwing. "TEST KEYWORD" is selected on a component's field.
"Fields": {
"heading": {
"DateTimeValues": [],
"FieldType": 0,
"KeywordValues": [],
"Keywords": [],
"LinkedComponentValues": [],
"Name": "heading",
"NumericValues": [],
"Value": "Keyword Test",
"Values": [
"Keyword Test"
],
"XPath": "tcm:Content/custom:KeywordTest/custom:heading"
},
"keyword": {
"CategoryId": "tcm:65-17-512",
"CategoryName": "Font Size",
"DateTimeValues": [],
"FieldType": 3,
"KeywordValues": [
{
"Description": "",
"Id": "tcm:65-1606-1024",
"Key": "",
"MetadataFields": {},
"ParentKeywords": [],
"Path": "\Font Size\TEST KEYWORD",
"TaxonomyId": "tcm:65-17-512",
"Title": "TEST KEYWORD"
},
{
"Description": "",
"Id": "tcm:65-1606-1024",
"Key": "",
"MetadataFields": {},
"ParentKeywords": [],
"Path": "\Font Size\TEST KEYWORD",
"TaxonomyId": "tcm:65-17-512",
"Title": "TEST KEYWORD"
},
{
"Description": "",
"Id": "tcm:65-1606-1024",
"Key": "",
"MetadataFields": {},
"ParentKeywords": [],
"Path": "\Font Size\TEST KEYWORD",
"TaxonomyId": "tcm:65-17-512",
"Title": "TEST KEYWORD"
},
{
"Description": "",
"Id": "tcm:65-1606-1024",
"Key": "",
"MetadataFields": {},
"ParentKeywords": [],
"Path": "\Font Size\TEST KEYWORD",
"TaxonomyId": "tcm:65-17-512",
"Title": "TEST KEYWORD"
},
How can I fix this problem?
Regards,
UPDATE:
In ContentModel.cs, there are propeties "Keywords" and "KeywordValues", and both of them use "KeywordValues" in set and get. In this case, when "Deserialize" is called from BaseComponentTemplate class, number of keyword field's value increase twofold. So Those properies should be separeted like following.
public List<Keyword> Keywords
{
get;
set;
}
[XmlIgnore]
IList<IKeyword> IField.Keywords
{
get { return Keywords.ToList<IKeyword>(); }
}
public List<Keyword> KeywordValues
{
get;
set;
}
[XmlIgnore]
IList<IKeyword> IField.KeywordValues
{
get { return KeywordValues.ToList<IKeyword>(); }
}
After that, modify source code where using those properties,ContentModel.cs and FieldBuilder.cs.