Unable to call sling model class from servlet
I am trying to call one of the sling model methods from servlet but I could not adapt the resource object to the sling model.
Here is my sling model.
@Model(
adaptables = { SlingHttpServletRequest.class, Resource.class },
adapters = ProductDetail.class,
resourceType = ProductDetailImpl.RESOURCE_TYPE)
@Exporter(
name = CommonConstants.JACKSON,
extensions = CommonConstants.JSON,
options = { @ExporterOption(
name = CommonConstants.SERIALIZATION_FEATURE + "." + CommonConstants.WRAP_ROOT_VALUE,
value = CommonConstants.TRUE) })
public class ProductDetailImpl implements ProductDetail
{
@JsonProperty("productDetail")
@Override
public String getProductDetail() {
return productDetail;
}
}
I am trying to call the getEventBeanList method in my below servlet, I can see the valid Resource object and when I try to adaptTo this resource to sling model class I get a null pointer exception. Any ideas why I am getting NPE?
[UPDATE]
I tried to check the status using http://localhost:4502/system/console/adapters. Interestingly my sling model class is marked as red but there is no reason given. In fact the sling model works as expected individually but I am not sure why this is marked in red color. Moreover all working sling models are marked as red but it is working as expected.

protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
throws ServletException, IOException {
Resource resource = request.getResourceResolver().getResource("/content/actualcontent");
LOGGER.info("test 1--- "+resource.getResourceType()); //platform/component/content/produtdetail
boolean isValidResource = resource.isResourceType("platform/component/content/produtdetail");
LOGGER.info("test 2-- "+ isValidResource);
if(isValidResource && "platform/component/content/produtdetail".equalsIgnoreCase(resource.getResourceType())) {
ProductDetailImpl product = resource.adaptTo(ProductDetailImpl.class);
String productDetail = product.getProductDetail();
LOGGER.info("productDetail: " +productDetail);
}
}



