Using Multiple Selectors
Although not a standard use case, it is possible to configure multiple selectors in addition to the model
selector.
https://<server>:<port>/content/page.model.selector1.selector2.json
However in such a case the model
selector must be the first selector and the extension must be .json
.
Annotate the Sling Model Interface
To be taken into account by the JSON Exporter framework, the Model interface should implement the ComponentExporter
interface (or ContainerExporter
, if there is a container component).
The corresponding Sling Model interface ( MyComponent
) would be then annotated using Jackson annotations to define how it should be exported (serialized).
The Model interface must be properly annotated to define which methods should be serialized. By default, all methods that respect the usual naming convention for getters is serialized and derives their JSON property names naturally from the getter names. This can be prevented or overridden using @JsonIgnore
or @JsonProperty
to rename the JSON property.
Example
The Core Components have supported JSON export since release 1.1.0 of the core components and can be used as a reference.
For an example, see the Sling Model implementation of the Image Core Component and its annotated interface.
CODE ON GITHUB
You can find the code of this page on GitHub
- Open aem-core-wcm-components project on GitHub
- Download the project as a ZIP file