How to get value of a list of list of RichText or RichTextData

One of the ContentModelData returns content in the below format.

Code 1

content =  {question=Question 1?, answer={paraContent=RichTextData(fragments=[No. Answer 1 <strong>Strong text here</strong> Answer continues <br /> Answer para 2.])}}


question has value of type String, and answer is a list of paragraphs containing heading, list of paraContent. List of paracontent is actually a list of RichText. Now sometimes paraContent is simply a list of RichText fields but when we create RichText Data, RichTextData fragments are created. I have tried many methods.

Code 2

1. paraMultiLevel= (List<ParagraphMultiLevel>)



None of the above populates my entity viewModel. I am getting an exception

com.sdl.dxa.api.datamodel.model.ContentModelData cannot be cast to java.util.List

How can I fetch the Answer value and set it on a List <List<ParagraphMultiLevel> so I can access it in my view?

Update on 04/04/2018

When I originally tried to convertEntites(List<ComponentMetadata>) (see code 3), it returned null values so then I had to manually iterate over the list of ids and got the EntityModelData using DefaultModelService.loadEntity(). From the EntityModelData I get the ContentModelData (see Code 1). I want to set my customTeaser.content with ContentModelData.get("answer").

Code 3

try { dynamicList.setQueryResults(customContentProvider._convertEntities(components, dynamicList.getEntityType(), localization), query.isHasMore());
} catch (DxaException e) {
throw new ContentProviderException("Cannot populate a dynamic list " + dynamicList.getId() + " localization " + localization.getId(), e);
}


returned [ContentTeaser(headline=null, introduction=null, content=null,...

Code 4

 @SemanticEntities({
@SemanticEntity(entityName = "FAQs", vocabulary = SDL_CORE, prefix = "f")
})

public class ContentTeaser extends AbstractEntityModel {

@SemanticProperty("f:question")
@JsonProperty("Introduction")
private String introduction;

@JsonProperty("Content")
private List<ParagraphMultiLevel> content;
}


Code 5

@SemanticEntity(entityName = "ParagraphMultiLevel", vocabulary = SDL_CORE, prefix = "pml")
@Data
@EqualsAndHashCode(callSuper = true)
public class ParagraphMultiLevel extends AbstractEntityModel {

@SemanticProperty("pml:paraContent")
@JsonProperty("ParaContent")
private List<RichText> paraContent;

@SemanticProperty("pml:subParagraph")
@JsonProperty("SubParagraph")
private List<SubParagraphLevel2> subParagraph;

@SemanticProperty("pml:paraFootnote")
@JsonProperty("ParaFootnote")
private List<RichText> paraFootnote;
}

• How did you define your View Model classes? And where are you trying to use this mapping logic? Direct access to the R2 Data Model (e.g. ContentModelData) is only expected in Model Builders, which is considered an advanced extension point which is normally not needed. – Rick Pannekoek Apr 4 '18 at 5:57
• Thanks @RickPannekoek for responding. I have updated my question to explain why I needed to access the R2 Data Model. – Rache Apr 4 '18 at 6:53
• @RickPannekoek please also take a look at another post which explains why we had to opt for this approach (directly accessing R2 data model). We were unable to populate entities/models using the standard DynamicList functionality. tridion.stackexchange.com/questions/18664/… – Husain Zahid Apr 4 '18 at 7:05

It seems you are trying to mix the R2 Data Model (e.g. ContentModelData) with your Strongly Typed View Models (e.g. ParagraphMultiLevel). That doesn’t work.