Expand my Community achievements bar.

SOLVED

How to custmize default sling content exporter behaviour in AEM?

Avatar

Level 9

I want to export the entire page to front end application. The page may contain 1 or 2 text component and image etc. Need to expose all of it is content. for example, http://localhost:4502/editor.html/content/we-retail/language-masters/en/men.model.tidy.json. This will give me the entire page content but along with some misc properties, like lastModifiedDate, allowedComponents, replicatedBy.

 

Mario248_0-1655297444853.png

 

Is there a way to exclude these properties (lastModifiedDate, allowedComponents etc)?

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Mario248 ,
Ideally you should not customised existing servlet. If your page structure is fixed or at least you know combinations of components. Then you can easily write a resource type servlet to expose/export required custom content. Add some different selector to differentiate from default servlet.  

View solution in original post

9 Replies

Avatar

Community Advisor

hi @Mario248 

 

You can implement a custom model and then pick the properties you want to have in the json.

 

Thanks,

Pallavi Shukla

Avatar

Community Advisor

Hi @Mario248 ,

As per @Pallavi_Shukla_ suggested yes, you can do it through Sling Model Exporter by annotating @JsonIgnore to the variable which you don't want to expose.

fore more details please have a look at this article: https://experienceleague.adobe.com/docs/experience-manager-learn/foundation/development/develop-slin...

Hope that helps you!

Regards,

Santosh

Avatar

Level 9

Yeah I know we can create a model class for a specific component meaning we can create a model class for specific resource type but how do we do it for the entire page? like in my description, I want to export the entire page (/content/we-retail/language-masters/en/men.model.tidy.json) meaning all the component content to be exported. how do we do this at page level ?

 

Also please tell if we can tweak OOTB exporter with exclude properties ?

Avatar

Community Advisor

@Mario248 honestly, I'm not sure whether we can able to tweak OOTB API. 

However, to answer your first question - please refer this article to customize page properties: https://www.linkedin.com/pulse/how-customize-properties-image-converted-json-aem-65-ragul-r

 

Avatar

Employee Advisor

The SlingModelExporter itself does not know about the concept of a page, it just knows itself (a model object), and it can serialize all its members into JSON.

 

That means if you want to export the page itself as a hierarchical JSON structure, your models needs to have references to all sub-models (which themselves can have references to their own sub-models). That should work, although I have never tried it out myself.

 

The problem is most often on the consuming side, as the result most likely resembles the component model of the page 1:1, thus often creating a very flexible (read: unpredictable) JSON, which is hard consume programmatically. Probably that's the reason why there's not much tooling available fro it.

 

 

 

 

Avatar

Correct answer by
Community Advisor

Hi @Mario248 ,
Ideally you should not customised existing servlet. If your page structure is fixed or at least you know combinations of components. Then you can easily write a resource type servlet to expose/export required custom content. Add some different selector to differentiate from default servlet.