Develop Sling Model Exporters
This technical walk through walks through setting up AEM for use with Sling Model Exporter, enhancing an existing Sling Model using the Exporter framework to rendition as JSON, and how to use Exporter options and Jackson annotations to further customize the output.
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 an can be exported as a different Java object, or more commonly, serialized into a different format such as JSON.
Configuring AEM for Sling Model Exporter
Sling Model Exporter is a feature of the Apache Sling project and not directly bound to the AEM product release cycle. Sling Model Exporter is compatible with AEM 6.3 and later.
The use-case for Sling Model Exporter
Creating a Sling Model Exporter
Enabling Exporter support on a Sling Model is as easy as adding the @Exporter annotation to the Java class.
Applying Sling Model Exporter options
Sling Model Exporter supports passing per-model Exporter options to the Exporter implementation to drive how the Sling Model is finally exported. These options generally apply "globally" to how the Sling Model is exported, versus per data point which can be done via inline annotations described below.
Jackson Exporter options include:
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.