1

I have created a component the fields of which have been mapped to a sling model. To get the data of the sling as JSON I have enabled Sling exporter as shown in the code below -

@Model(adaptables = { Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL, resourceType = "XXX/components/content/XXX")
@Exporter(name = "jackson", extensions = "json")
public interface ProofPointsModel {

    @Inject
    List<ProofPointsList> getProofPoint();

    @Model(adaptables = { Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
    interface ProofPointsList {

        @Inject
        String getProofText();

        @Inject
        String getProofIcon();

    }
}

This works perfectly and I am able to see the JSON data when hit the end point from my browser. I want to render this entire json object in my component's HTL. Is there an elegant way of doing this? I dont want to create an additional request to retrieve this data. Basically I want to call this sling exporter from within my component and render the json object as is.

Thanks

Archit Arora
  • 2,508
  • 7
  • 43
  • 69
  • Does this answer your question? [Get .model.json as String](https://stackoverflow.com/questions/57527180/get-model-json-as-string) – Vlad May 31 '21 at 12:06

1 Answers1

0

Unfortunately, HTL does not allow doing these "server-side includes". The workaround is to expose the JSON in a getJson method of your model: Get .model.json as String

Vlad
  • 10,602
  • 2
  • 36
  • 38