contentful.java
contentful.java copied to clipboard
Unwrap a collection of multiple content types
How can a collection of different content types can be unwrap?
our json preview looks like this
"name": "Activities",
"type": "Array",
"localized": false,
"required": true,
"validations": [],
"disabled": false,
"omitted": false,
"items": {
"type": "Link",
"validations": [
{
"linkContentType": [
"practiceMode",
"videoLesson",
"feedbackMode"
]
}
],
"linkType": "Entry"
}
}
but inside our model what is the best approach to unwrap it?
@ContentfulField var activities: <....>? = null
Try this: https://www.contentfulcommunity.com/t/unwrapping-nested-entries-of-varying-types/7056
@TransformQuery.ContentfulEntryModel(
value = "example",
additionalModelHints = {PracticeMode.class, VideoLesson.class, FeedbackMode.class})
class Example {
@TransformQuery.ContentfulField("activities")
private Object activities;
}
Where PracticeMode and others are also ContentfulEntryModels.