I have some content types defined in a contentful space and I am trying to fetch some content I've created.
These are the contentTypes
I've created:
{
"name": "Configuration",
"description": "configuration",
"displayField": "name",
"fields": [
{
"id": "name",
"name": "Name",
"type": "Symbol",
"localized": false,
"required": true,
"validations": [
{
"unique": true
}
],
"disabled": false,
"omitted": false
},
{
"id": "pages",
"name": "Pages",
"type": "Array",
"localized": false,
"required": true,
"validations": [],
"disabled": false,
"omitted": false,
"items": {
"type": "Link",
"validations": [
{
"linkContentType": [
"Page"
]
}
],
"linkType": "Entry"
}
}
],
"sys": {
...
}
}
{
"name": "Page",
"description": "Page",
"displayField": "name",
"fields": [
{
"id": "name",
"name": "Name",
"type": "Symbol",
"localized": false,
"required": true,
"validations": [
{
"unique": true
}
],
"disabled": false,
"omitted": false
},
{
"id": "title",
"name": "Title",
"type": "Symbol",
"localized": true,
"required": true,
"validations": [],
"disabled": false,
"omitted": false
},
{
"id": "shortTitle",
"name": "Short title",
"type": "Symbol",
"localized": true,
"required": true,
"validations": [],
"disabled": false,
"omitted": false
},
{
"id": "description",
"name": "Description",
"type": "Symbol",
"localized": true,
"required": true,
"validations": [],
"disabled": false,
"omitted": false
},
{
"id": "sections",
"name": "Sections",
"type": "Array",
"localized": false,
"required": true,
"validations": [],
"disabled": false,
"omitted": false,
"items": {
"type": "Link",
"validations": [
{
"linkContentType": [
"Section"
]
}
],
"linkType": "Entry"
}
}
],
"sys": {
...
}
}
{
"name": "Section",
"description": "section",
"displayField": "name",
"fields": [
{
"id": "name",
"name": "Name",
"type": "Symbol",
"localized": false,
"required": true,
"validations": [
{
"unique": true
}
],
"disabled": false,
"omitted": false
},
{
"id": "provider",
"name": "Provider",
"type": "Symbol",
"localized": false,
"required": true,
"validations": [
{
"in": [
"1",
"2",
"3"
]
}
],
"disabled": false,
"omitted": false
},
{
"id": "maxDisplayLimit",
"name": "Max display limit",
"type": "Integer",
"localized": false,
"required": true,
"validations": [],
"disabled": false,
"omitted": false
},
{
"id": "productList",
"name": "Product IDs",
"type": "Array",
"localized": false,
"required": false,
"validations": [
{
"size": {
"min": 1,
"max": 50
}
}
],
"disabled": false,
"omitted": false,
"items": {
"type": "Symbol",
"validations": []
}
}
],
"sys": {
...
}
}
And my Java code to fetch them:
client = CDAClient.builder()
.setSpace(space)
.setEnvironment(environment)
.setToken(accessToken)
.build();
client.observeAndTransform(Configuration.class)
.withLocale(locale)
.include(MAX_DEPTH)
.all()
.blockingFirst();
and I've modeled such contentTypes
like:
@TransformQuery.ContentfulEntryModel("Configuration")
public record Configuration(@TransformQuery.ContentfulField String name,
@TransformQuery.ContentfulField List<Page> pages) {
}
@TransformQuery.ContentfulEntryModel("Page")
public record Page(@TransformQuery.ContentfulField String name,
@TransformQuery.ContentfulField String title,
@TransformQuery.ContentfulField String shortTitle,
@TransformQuery.ContentfulField String description,
@TransformQuery.ContentfulField List<Section> sections) {
}
@TransformQuery.ContentfulEntryModel("Section")
public record Section(@TransformQuery.ContentfulField String name,
@TransformQuery.ContentfulField String provider,
@TransformQuery.ContentfulField Integer maxDisplayLimit,
@TransformQuery.ContentfulField List<String> productList) {
}
When the code reaches the .observeAndTransform
method I always get:
Cannot create new instance of custom model
I've also tried to remove everything a part the name of the Configuration contentType. I've also double-checked all the contentTypes ids and contentField ids to ensure the mapping was correct. Anyone has an idea?