I18n json as API | Community
Skip to main content
New Participant
Sep 9, 2020 10:47 AM UTC
Solved

I18n json as API

Hi,

I am trying to build a API on top of i18n. So I can expose it for other channels to consume it. Essentially, I don't want to expose the full json dict. 

I want something like this, <domain>/<country>/<lang>/<pagecode>/<feature>.json and expecting it to give me the filtered json for the feature. I could do it for .html. which is giving me the json (as string) in the Html output. But when I use .json it is not. I have a json rendition (json.jsp). It is Getting handled by default servlet and giving me error. Please help. I checked .json extension is there in the sling get servlet. 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
ChitraMadan
ChitraMadanAccepted solution
New Participant
Sep 9, 2020 9:36 PM UTC

Hi @sagarneelb ,

 

You can have a custom servlet based on resource type or selector e.g.

You can call<domain>/<country>/<lang>/<pagecode>/<feature>.jsondict

 

@Component(metatype = false)
@Service(Servlet.class)
@Properties({
@Property(name = "sling.servlet.selectors", value = { "jsondict" }) })
public class DefaultDictionarySelector extends SlingSafeMethodsServlet {
////// Filter logic based on feature
///// Write json
}

 

4 replies

ChitraMadan
ChitraMadanAccepted solution
New Participant
Sep 9, 2020 9:36 PM UTC

Hi @sagarneelb ,

 

You can have a custom servlet based on resource type or selector e.g.

You can call<domain>/<country>/<lang>/<pagecode>/<feature>.jsondict

 

@Component(metatype = false)
@Service(Servlet.class)
@Properties({
@Property(name = "sling.servlet.selectors", value = { "jsondict" }) })
public class DefaultDictionarySelector extends SlingSafeMethodsServlet {
////// Filter logic based on feature
///// Write json
}

 

Translate
Shashi_Mulugu
New Participant
Sep 9, 2020 5:51 PM UTC

@sagarneelb can you please create a resource type servlet with extension JSOn and try please?

Translate
Employee
Sep 9, 2020 2:47 PM UTC

If the JSON request is being handled by org.apache.sling.servlets.get.DefaultGetServlet -- then why not set enable.json to false?

Translate
New Participant
Oct 16, 2020 11:30 AM UTC
I tried that, to make it false. did not help 😞
Translate