Expand my Community achievements bar.

Adobe Summit 2025: AEM Session Recordings Are Live! Missed a session or want to revisit your favorites? Watch the latest recordings now.
SOLVED

AEM Sling Model Jackson Exporter returns null for nested objects

Avatar

Level 2

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
}

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @MatthewDa19,

I think you missed adding Jackson exporter annotations on the nested model (AuthorModel)

@Exporter(name = "jackson", extensions = "json")

Nested models need the @Exporter annotation because Sling’s Jackson exporter only serializes models explicitly registered for export. Without it, the nested object isn’t recognized as exportable and will be skipped or serialized as null.

For more detailed information, you can refer to the official documentation:

Hope that helps!


Santosh Sai

AEM BlogsLinkedIn


View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @MatthewDa19,

I think you missed adding Jackson exporter annotations on the nested model (AuthorModel)

@Exporter(name = "jackson", extensions = "json")

Nested models need the @Exporter annotation because Sling’s Jackson exporter only serializes models explicitly registered for export. Without it, the nested object isn’t recognized as exportable and will be skipped or serialized as null.

For more detailed information, you can refer to the official documentation:

Hope that helps!


Santosh Sai

AEM BlogsLinkedIn


Avatar

Community Advisor

Hi @MatthewDa19 ,

Your nested model (AuthorModel) is missing the @Exporter annotation, which is required for Sling to serialize it properly using Jackson.

Update your nested model like this:

@Model(adaptables = Resource.class, 
       defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = "jackson", extensions = "json") //  THIS IS REQUIRED
public class AuthorModel {

    @ValueMapValue
    private String name;

    @ValueMapValue
    private String role;

    // getters...
}

Why this works:

Sling’s Jackson exporter only serializes classes explicitly registered with @Exporter. Without it, nested objects (like List<AuthorModel>) return null.

After Fix – Output Will Be:

{
  "title": "Sample Article",
  "description": "A test article",
  "authors": [
    {
      "name": "Jane Doe",
      "role": "Editor"
    }
  ]
}

 

Regards,
Amit

Avatar

Level 2

@AmitVishwakarma What's the difference in your answer than @SantoshSai posted? Seems you are wasting your energy here by copy pasting answers from ChatGpt!