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.
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.
Enabling Exporter support on a Sling Model is as easy as adding the
@Exporter annotation to the Java class.
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:
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.