Expand my Community achievements bar.

SOLVED

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

Avatar

Level 3

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?

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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)

 

View solution in original post

11 Replies

Avatar

Correct answer by
Community Advisor

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)

 

Avatar

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

Avatar

Community Advisor

Hi @bsr060893,

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

Avatar

Level 3
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

Avatar

Community Advisor

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.

Avatar

Level 3

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

Avatar

Community Advisor

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)

Avatar

Level 5

@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();

Avatar

Level 3

Hi @raghavc ,

 

I have many such components which doesn't have the model exporter and saves the content data as the child nodes under the component node in content tree.

 

Is there any generic solution for including he child nodes?

Avatar

Level 5
Is your component extending core components ? Without a sling exporter implementation, sling would export only the default attributes which start with colon.

Avatar

Level 3

Some of the components are really old and not extending core components.

I am looking for a way customizing the json