Sling Model Exporter HTTP Request flow
Apache Sling Model Exporter comes with a Sling provided Jackson Exporter that automatically serializes an “ordinary” Sling Model object into JSON. The Jackson Exporter, while quite configurable, at its core inspects the Sling Model object, and generates JSON using any “getter” methods as JSON keys, and the getter return values as the JSON values.
The direct serialization of Sling Models allows them to service both normal Web requests with their HTML responses created using the traditional Sling Model request flow (see above), but also expose JSON renditions that can be consumed by web services or JavaScript applications.
This flow describes the flow using the provided Jackson Exporter to produce JSON output. Use of custom exporters follow the same flow but with their output format.
-
HTTP GET Request is made for a resource in AEM with the selector and extension registered with the Sling Model’s Exporter.
Example:
HTTP GET /content/my-resource.model.json
-
Sling resolves the the requested resource’s
sling:resourceType
, selector and extension to a dynamically generated Sling Exporter Servlet, which is mapped to the Sling Model with Exporter. -
The resolved Sling Exporter Servlet invokes the Sling Model Exporter against the Sling Model object adapted from the request or resource (as determined by the Sling Models adaptables).
-
The exporter serializes the Sling Model based on the Exporter Options and Exporter-specific Sling Model annotations and returns the result to the Sling Exporter Servlet.
-
The Sling Exporter Servlet returns the JSON rendition of the Sling Model in the HTTP Response.