Search code examples
jacksonaemslingsightlysling-models

How to display a json response mapped pojo in sightly


I have a sling servlet that invokes a 3rd party api and fetches a json response. I have mapped the json response to a pojo class using Jackson. I now have to display this dynamically fetched and mapped response in sightly. How do i do that? I am stuck after the response mapping


Solution

  • With the new version of Sling Models, you can directly expose a model as a Servlet by specifying a resource type and the selector to use in your model annotations. When the Model is loaded into Apache Sling, it automatically registers a Servlet corresponding to the model, allowing you to with nearly zero additional code, create a Servlet to access a JSON representation of the model. That’s super cool!

    The above life makes your Life Easier!!

    You can have all your objects in Sling Model. Since the sling model acts as a servlet You can make the AJAX call and get a real-time response.

    Please refer to this document. https://blogs.perficient.com/2018/07/26/no-servlets-required-exporting-data-with-sling-models/