Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-6183

Sling Models - Provide a mechanism to export model objects via servlets

    XMLWordPrintableJSON

    Details

      Description

      I would like to introduce a new feature to Sling Models named Exporters.

      Exporters allow for a model class to be exported into a specific Java object type in a automated fashion. The simplest example is to support String serialization, although different Exporters may support whatever target classes they see fit.

      Exporters are implemented through an SPI. This initial contribution includes an exporter using the Jackson library which supports both String and Map exports.

      Interfacing with the registered Exporters is done through three new methods on the ModelFactory interface:

      • exportMode
      • exportModelForResource
      • exportModelForRequest

      In addition, using these functionality, model objects can have automatically-registered servlets which export the model (from either the request or the request's resource) as a String and then serve that String to the client.

      Registering these servlets is done through a new annotation named @Exporter

      For example, you might add this annotation to a Model class

      @Exporter(name = 'jackson', extension = 'json')

      This will register a servlet for the model's resource type with the extension `json` and a selector of `model` (by default, the @Exporter annotation can also define a different selector).

        Attachments

        1. SLING-6183.patch
          77 kB
          Justin Edelson

          Activity

            People

            • Assignee:
              justinedelson Justin Edelson
              Reporter:
              justinedelson Justin Edelson
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: