AEM Sling Model Jackson Exporter returns null for nested objects
Hi all,
I’m trying to expose a Sling model using the Jackson exporter in AEM as a Cloud Service, but I’m facing an issue where nested objects or lists return null in the JSON output, even though the values are present in the JCR.
Here's a simplified version of my code:
Sling Model
@Model(adaptables = Resource.class,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL,
resourceType = "myproject/components/article",
adapters = ArticleModel.class)
@Exporter(name = "jackson", extensions = "json")
public class ArticleModel {
@ValueMapValue
private String title;
@ValueMapValue
private String description;
@ChildResource
private List<AuthorModel> authors;
// getters...
}Nested Model
@Model(adaptables = Resource.class,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class AuthorModel {
@ValueMapValue
private String name;
@ValueMapValue
private String role;
// getters...
}Expected Output
{
"title": "Sample Article",
"description": "A test article",
"authors": [
{
"name": "Jane Doe",
"role": "Editor"
}
]
} Actual Output
{
"title": "Sample Article",
"description": "A test article",
"authors": null
}
