Looking for information to create a custom JSON rendering | Community
Skip to main content
October 16, 2015
Solved

Looking for information to create a custom JSON rendering

  • October 16, 2015
  • 5 replies
  • 2078 views

I need to create a rendering that is very similar to page.infinity.json, only mine would not include any jcr and cq fields.

Any links to information on this would be appreciated, I'm not having much luck finding what I need.

Thanks,

Doug

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Runal_Trivedi

You can create a Sling Servlet and bind it with the resourceType of your basepage component (assuming you already have basepage component for all page components) along with resourceType binding, you can also specify your custom selector (like .infinity) and extension as .JSON.

Doing so, now using your servlet, you can create any JSON response that you need.

Refer to following link to know more about binding servlet to resourcetype - https://sling.apache.org/documentation/the-sling-engine/servlets.html#example-registration-by-resource-type-etc

Also there was recently a query raised on binding servlet to resourceType, kindly refer that as well - http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__ejtw-_i_am_deployingas.html

Hope it helps.

Cheers

- Runal

5 replies

Runal_Trivedi
Runal_TrivediAccepted solution
Level 6
October 16, 2015

You can create a Sling Servlet and bind it with the resourceType of your basepage component (assuming you already have basepage component for all page components) along with resourceType binding, you can also specify your custom selector (like .infinity) and extension as .JSON.

Doing so, now using your servlet, you can create any JSON response that you need.

Refer to following link to know more about binding servlet to resourcetype - https://sling.apache.org/documentation/the-sling-engine/servlets.html#example-registration-by-resource-type-etc

Also there was recently a query raised on binding servlet to resourceType, kindly refer that as well - http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__ejtw-_i_am_deployingas.html

Hope it helps.

Cheers

- Runal

October 16, 2015

Still struggling a bit - just trying to create a sling servlet has been problematic.  I followed Scott's write up, but I keep running into errors.  I believe they may be related to OS and app versions.

Do you know of any other examples to create a servlet and maybe some code samples for accomplishing a custom selector/rendering?

Level 2
October 16, 2015

Another way to do this creating custom format JSP instead of servlet. For the require page component add the additional format  like below.

/apps/sample/components/article/

----article.jsp

----article.json.jsp. 

In the json jsp get the current node and traverser and build the json in the required format. Make sure to set the response content type to JSON as below.

response.setContentType("application/json");

This will mask the default json format for this template. If you wish not to we can specify another custom format 

smacdonald2008
Level 10
October 16, 2015

Is this the write you are referring to:

https://helpx.adobe.com/experience-manager/using/resourcetypes.html

There is a package too with this.

There has been quite a few community members that have got this working. I want to know if this works for you and if not - why. 

Does the package work. Try installing the package. If it does not work- let me know. I can setup a connect session to get to the bottom of why this content is not running within your environment. 

smacdonald2008
Level 10
October 16, 2015

This one just returns HTML:

[img]html.png[/img]

YOu can code the servlet to return JSON data.