contentful.java icon indicating copy to clipboard operation
contentful.java copied to clipboard

Unwrap a collection of multiple content types

Open alejandrorangel opened this issue 2 years ago • 1 comments

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

alejandrorangel avatar Oct 31 '23 10:10 alejandrorangel

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.

gediminasmorkys avatar May 29 '24 12:05 gediminasmorkys