Hi @harshak11490245 ,
Your resource resolver can't recognize URL. You should find content fragment by path e.g. /content/dam/wknd-shared/en/adventures/napa-wine-tasting/napa-wine-tasting, adapt to ContentFragment model and export it with Jackson exporter.
Below you can find a code an example of OSGi component how to get Content Fragment in JSON programmatically:
@Component
public class CfConverter {
@Reference
private org.apache.sling.models.factory.ModelFactory modelFactory;
public String exportCfInJSON(ResourceResolver resourceResolver, String cfPath) {
Resource cfResource = resourceResolver.getResource(cfPath);
if (cfResource == null) {
return null;
}
ContentFragment model = cfResource.adaptTo(com.adobe.cq.dam.cfm.ContentFragment.class)
if (model == null) {
return null;
}
return modelFactory.exportModel(model, 'jackson', String.class, Map.of());
}
}
Best regards,
Kostiantyn Diachenko.