Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is the TestComponentModel.java, which can be used as sling Model Exporters.
package com.mycompany.myproject.sling.models;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.ExporterOption;
import org.apache.sling.models.annotations.Model;
import javax.inject.Inject;
import javax.inject.Named;
@Model(adaptables = Resource.class, resourceType = { "weretail/components/content/heroimage" }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = "jackson", extensions = "json", options = { @ExporterOption(name = "SerializationFeature.WRITE_DATES_AS_TIMESTAMPS", value = "true") })
public class ModelComponent {
@Inject
String title;
@Inject
String heading;
@Inject
String buttonLabel;
@Inject
String buttonLinkTo;
@Inject
String fileReference;
@Inject
@Named("sling:resourceType")
String slingResourceType;
public String getHeading() {
return heading;
}
public String getButtonLabel() {
return buttonLabel;
}
public String getButtonLinkTo() {
return buttonLinkTo;
}
public String getSlingResourceType() {
return slingResourceType;
}
public String getTitle() {
return title;
}
public String getFileReference() {
return fileReference;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment