@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) })
@JsonRootName("ProductDetail")
public class ProductDetailImpl implements ProductDetail
{
...
}
Solved! Go to Solution.
Views
Replies
Total Likes
Hi Mario,
Inside execute method of your workflow, you can use ResorceResolver rr; to get resource and then ask adaptTo method to get your Model.
Something along these lines would work:
Resource productResource = rr.getResourceResolver().getResource(workflow.getWorkflowData().getPayload().toString());
ProductDetail product = productResource.adaptTo(ProductDetail.class);
Regards,
Peter
Hi Mario,
Inside execute method of your workflow, you can use ResorceResolver rr; to get resource and then ask adaptTo method to get your Model.
Something along these lines would work:
Resource productResource = rr.getResourceResolver().getResource(workflow.getWorkflowData().getPayload().toString());
ProductDetail product = productResource.adaptTo(ProductDetail.class);
Regards,
Peter
Thanks for your response. Yeah, I could adapt resource object to my model class. But how to get the json response with "product" obj? I could see all the methods of "product" object but there is no method available to get all field as json value. Can you guide me please ?
Hi Mario,
Once you get hold of your object you can ask Jackson to render the object for you:
JsonNode jsonNode = new ObjectMapper().valueToTree(product);
String json = jsonNode.writeValueAsString(jsonNode);
Regards,
Peter
Great, It works as you mentioned. Thanks for your response.
Views
Likes
Replies