March 22, 2020
Estimated Post Reading Time ~

What is Sling Model Exporters?

Sling Models:
Sling Models are business objects that represent sling resources or sling request objects in AEM. In another way, Sling Models let you map Java objects to Sling resources.

Sling Models Exporter
Sling Model Exporters helps to export the model as a different Java object (serialized into a different format such as JSON) by adding annotations to the Sling Model. The model is programmatically exported by calling the ModelFactory method exportModel().

Jackson exporter
Jackson exporter which is used in Sling allows converting Sling Model into a Java Map object. Jackson JSON exporter helps to export Sling Models as JSON objects, which can be accessed from other third party web service applications, Javascript application, etc.

Sling Model Exporter is available from Sling Models version v1.3.0.

Pictorial representation of Sling Model Vs Sling Model Exporter

Can I use Sling Model Exporters with versions prior to AEM 6.3?

Yes AEM 6.3 onward no extra dependencies required to use Sling Model Exporters.

But versions prior to AEM 6.3 requires the installation of below-bundled packages from,
Sling > Downloads
· Models API 1.3.0+
· Models Implementation 1.3.0+
· Models Jackson Exporter 1.0.0
· AEM 6.2 Communities/Livefyre - FP2

How to add an exporter framework to an existing sling model?

1) Add a resource type to a model,

Add below line in @Model code block of the Sling Model.

resourceType = "[The type of the resource which we are requesting]";

2) Add a new annotation,

@Exporter ( name = "jackson", extensions = "json")
Associate a model class with a resource in SlingDocumentation here

After building the code, invoke the resource with selector model.json

This will bring back the response in JSON format and the response is picked from the getter methods in the sling model class.

Sling Exporter Documentation



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.