Ad Code

Monday, June 12, 2017

Sling Model Exporter in AEM 6.3

Hello Everyone,

Sling Model Exporter was introduced in Sling Models v1.3.0. This new feature allows new annotations to be added to Sling Models that define how the Model can be exported as JSON.

Use Case: Now the question comes why sling model exporter. So the idea is if there is a sling model and you want to fetch the same properties as a JSON response,so there is no need to create a Sling Servlet. You just need to export your sling model  using jackson exporter and that’s all. Sling Model Exporter can be used as a web service or as a rest API.

In AEM 6.3, No external dependencies required.

Fig - Required Bundle for Sling Model Exporter

The felix console already contains:

  • Apache Sling Model API (1.3.0+)
  • Apache Sling Model Implementations (1.3.0+)
  • Apache Sling Model Exporter(1.0.6)

Now create a Sling Model, But before creating the sling model you need to add some dependency for building the project


Don’t forget to make an entry of sling model package in the maven-bundle plugin.
Fig - Sling Model Package entry in bundle POM.xml

Now Let’s take an example of a” Hero Image” component of we-retail:
Fig- Hero Component

The properties of the above component are being stored here:

Fig - Dialog Values of Hero Component

Sling Model without Exporter:
To enable sling model as an exporter,the @Exporter annotation is being used.

Make a rest call with the following format:


Note:”tidy” is a default selector to show the json response in a clean format.It is not mandatory at all.

JSON Response.PNG
Fig - Hero Component Dialog value in JSON Response from Sling Model Exporter 

@Model annotation contains:

1. resourceType: This property is of String or String[] type.
The resourceType helps to know that for which resources ,the sling model needs to be exported.

@Exporter annotation contains: Sling model provides "jackson" as exporter.
2. selector: The default value of the selector is "model".It can be override by writing this attribute.This attribute is optional.
3.extension: Sling Model needs to be exported as json.So extensions should be as “json”

Let's have a quick demo of Sling Model Exporter:

Jackson Exporter Options include:

Jackson Exporter Options help to manage the JSON response and control the output of the JSON

Let’s understand the Jackson Exporter Options With Example:

@ExporterOption(name = "MapperFeature.SORT_PROPERTIES_ALPHABETICALLY", value = "true")

By Default It’s value is false, then json response will be as it is.


When The value is true,then it sorts the json response alphabetically based on key.


Except this, MapperFeature and SerializationFeature exporter annotation has many more options.

Note: While the Apache Sling project provides the Jackson Exporter that serializes Sling Models to JSON, the Exporter framework also supports custom Exporters.

Applying Jackson Annotations:
Exporters implementations may also support annotations that can be applied inline on the Sling Model class, that can provide a finer level of control how the data is exported.

Here we go, how to use Jackson annotations with Sling Model Exporter:

To get a detailed knowledge of all the Jackson annotations, go through this link

If you have any query or suggestion then kindly comment or mail us at

Hope it will help you guys !!

Thanks and Happy Learning .


  1. Nice article. Does this support selective properties feature like query builder json servlet?

    1. Thanks for appreciations!

      What do you mean by selective properties feature here?

    2. Hi Saurabh,

      In the query builder json servlet when you use selective properties feature you can tell which fields can come in the response. In the same way for instance if my resource has many properties and in the exporter response if I want to a sub set of those properties. Can it be done?

    3. You can use Jackson Annotation @JsonIgnore for that.

  2. This comment has been removed by the author.

  3. What is the advantage of this exporter when I can also retrieve the json format using localhost:4502/path-to-resource.infinity.json ?

    Please help clarify the advantages.

    1. Ya ashish,this is really a good question, This exporter is not only just returning the values,you can return anything from this.Let's take an example,You have taken a path in the component dialog and just want to return all the children of that path as a json.So These kind of scenario's can be handled with this.

  4. you wrote this blog at 7:06 AM so did you sleep that night or entire night you wrote it ? Jokes apart , I appreciate your efforts in writing these blogs.

  5. Hi Shivani,

    I have faced below interview question

    I have a normal html form there are some fields like title ,name and descrption
    name would be the page name
    description would be the page description
    title would be the page title
    when i click on submit button on that form, the page is created in my crx console
    under some node structure

    how can i do this could you please help me?

    1. Hi Naveen,
      While clicking on submit button,you can hit a servlet which will be using ResourceUtil API or Node API to create a page and add properties in that.

  6. Hi Shivani,

    This is helpful article.

    But I see below compilation issue i.e. resourceTypes not found. I tried options to import resourceTypes, but have not found any. Do you know what the issue is?

    1. Hey Suneel, Check your Maven dependency .do you check your sling model dependency version 1.3.0?

  7. This comment has been removed by the author.

  8. Hey,

    Great blog!

    I was trying to access the component using this url http://localhost:4502/content/we-retail/ca/en/experience/jcr:content/root/hero_image.model.json
    but I am getting the following error: Could not inject all required fields into class com.adobe.cq.wcm.core.components.models.impl.v1.ImageImpl

    Could you please point out why this might be happening.

    Thanks & Regards,
    Prakash Iyer

    1. This comment has been removed by the author.

    2. Hi Prakash,
      The issue is with already created Sling Model com.adobe.cq.wcm.core.components.models.impl.v1.ImageImpl. This situation happens when you inject a lot of field in sling model as required but the resource dont have all the values of those all injections.You can just decompile the bundle and check what this model wants.

    3. Hello Shivani,

      Thanks for the quick reply.
      I have reinstalled the bundles for wcm components and still I am getting the same error and there are not many answers on google.
      Could you please give me some pointers as to what needs to be done.

      PS: I am a newbie and might not know all terms related to AEM

      Prakash Iyer

    4. Prakash,
      Give me some time. I will look into deep and get back to you.

    5. Hello Shivani,

      Did you get a chance to look into the issue? If so please get back as this is proving a blocker for me, I have searched a lot online but no success so far.

      Thanks in Advance

      Prakash Iyer

    6. This comment has been removed by the author.

    7. Hii Prakash,
      I checked the issue, There is a bundle in AEM 6.3 "Adobe Experience Manager Core WCM Components Core Bundle"
      In which you can see the model com.adobe.cq.wcm.core.components.models.impl.v1.ImageImpl.
      In that model, They have used SightlyWCMMode from import statement import com.adobe.cq.sightly.SightlyWCMMode;.
      I dont know why this thing is not working here. If you remove this, it will work fine. I teated it with my custom exporter with the same code.
      Looking more onto this that why wcmmode is not working.

    8. Hey Shivani,

      I located the Adobe Experience Manager Core WCM Components Core Bundle but could not find com.adobe.cq.wcm.core.components.models.impl.v1.ImageImpl within that model. Do not know what the issue seems to be.

      Prakash Iyer

    9. Can you please email me and get this resolved?

    10. I have sent you an email, with the entire stacktrace.

  9. HI i have a requirement like I am having an input field where i can enter text and on click of submit i have to pass the entered text to the sling models as a parameter and i have to print it returned from the slingmodels

  10. Hi Shivangi,
    Appreciate your effort to write this nice article.

    Lets assume in a page , we have two components (A & B). Custom sling model & exporter has been implemented for both components A & B. Now can we get the exported json response for both the components via a single page request ? Looks like if we request via page level then page level entry point model is considered in rendering the json ignoring the component models. Is the understanding correct ?

  11. HI Shivani,

    Thanks for this article.

    I have created exporter component and component added to the page.
    I am able to get the json response from below

    Can we get the same response using page URL like

    Here my page is find-an-agent and exporter component is iframe

    Thanks , Ramesh

  12. HI Shivani,
    I follwed the same step to create sling exporter but getting below error.
    Note :- "test1" is my selector
    Invalid recursion selector value 'test1'

    Cannot serve request to /content/aem63arch12/en/testexporter/jcr:content/root/responsivegrid/slingexporter.test1.json in

    Do you have any idea why i am getting this error?

  13. I have a scenario where i have created a custom sling exporter with some defined fields in JSON format. Is there a way we can Inject additional fields without doing code change as there may be need to add some fields later

  14. Hi Shivani !!! Hope your doing good .. my doubt was that I added a selector test to my exporter . When I tried to load my page with .test.json , call went to DefaultGet and I got error .. the extension only works when I use it contents under jcr:content/root/heroImage.test.html

  15. Hi Shivani
    When i am using model.json, i can get only first level of items, but it is nt as same as infinity.json.
    In my usecase i need same values as i get in infinity.json
    Can you please help me on that

  16. Hi Shivani , Can we export experience fragments as well ?

  17. I had one more question. What if my requirement is to render these json file details into some html page. Is that possible by using exporter or is there any other easy method?

  18. To access an AEM component json(publish URL) using third party micro Service, authentication is needed?