XF model.json not fetching the child nodes of the component

bsr060893

19-08-2020

Hi,

 

I used a image component for creating a XF.
My custom image component will store the file reference as the child of the image node in content tree.

My model.json is not able to retrive the properties on the child node but only from the component node i.e image node.

bsr060893_1-1597837743703.pngbsr060893_2-1597837997887.png

 

Is there a way to include the child nodes of the component as well?

 

Accepted Solutions (1)

Accepted Solutions (1)

Vijayalakshmi_S

MVP

19-08-2020

Hi @bsr060893,

Could you please confirm if your custom image component has a Sling Model and Exporter is enabled on the same via annotation.

Below link explains how to enable a JSON export for a component. 

https://docs.adobe.com/content/help/en/experience-manager-65/developing/components/json-exporter-com...

 

 

There is nothing like default exporter.

XF page or Site page is accessible via "model.json" is because the respective page component has Sling Model with Exporter. Also the container components used within in turn has its own Sling Model with Exporter. 

Given your existing set up, the only possible way to expose XF or Site Page as JSON would be to make use of JSON rendering of Sling Default Get Servlet.  - "tidy.infinity.json or tidy.-1.json" which will expose the entire node structure with utmost depth. (To avoid custom implementation)

 

my component dosent have the sling model exporter. I have observed that this is able to replicable with core components aswell.as well

Hi @bsr060893,

Could you please let know which exact core component you tried. 

I have added to image core component . This scenario I understand It didn't fetch as in the model exporter the child node property may not be included. I am trying to understand is a way to customize the output json

Hi @bsr060893,

Core Image component both v1 and v2 saves the path as property (fileReference) and not as child node. Also if we observe the Core Image component model, this particular property is ignored in JSON via @JsonIgnore and other related properties are exposed. 

As we are trying to get the JSON at XF level - xf page.model.json, it should be at respective page component model that we need to look into. 

Exposing child node shouldn't be a problem. Perhaps in this context of exposing it via XF JSON as a whole might be a concern.

Next steps:

I suggest you to try Sling Model with exporter for your custom image component and try exposing at component level (This is to check if  child node exposing is not a concern)

I will try in local in parallel and share my findings.

Hi @Vijayalakshmi_S

Most of my components does not have the exporters.

I am trying to find if any default exporter java class is doing the job for the components and customizing the class to include the child nodes.

But i am unable to find the class.

Let know if any default model exporter handler for the components known.

Thank you

Hi @bsr060893,

There is nothing like default exporter.

XF page or Site page is accessible via "model.json" is because the respective page component has Sling Model with Exporter. Also the container components used within in turn has its own Sling Model with Exporter. 

Given your existing set up, the only possible way to expose XF or Site Page as JSON would be to make use of JSON rendering of Sling Default Get Servlet.  - "tidy.infinity.json or tidy.-1.json" which will expose the entire node structure with utmost depth. (To avoid custom implementation)

Answers (1)

Answers (1)

raghavc

20-08-2020

@bsr060893 : 'path' node is still part of the Image component , So you can use the below code to read the properties of the path node in Image Sling Model class. As the path node will not have any sling resource type, sling exporter will not process it automatically. 

 

 

@Inject @Via(value = "path", type = ChildResource.class) String getPropertyName();