Expand my Community achievements bar.

SOLVED

AEM as a Cloud Service SPA React | Nested Multifield Json is not rendering in model.json

Avatar

Level 2

Hi,

 

I am using nested multifield in AEM SPA with react .When I am trying to access the <page url>.model.json, nothing is rendered. But, when I try to retrieve with component node path,<page-node-path>.model.json, then it returns the component json.

 

Please let me know how can I retrieve nested multifield values in page model.json

 

Multifield Node Structure:

Divya_13_0-1685563467337.png

 Page model.json:

Divya_13_2-1685563583095.png

Specific Component Model Json:

Divya_13_4-1685563697724.png

Code Snippet:

Divya_13_5-1685563765477.png

Divya_13_10-1685564157883.png

 

 

 

Divya_13_7-1685563838579.pngDivya_13_8-1685563852847.png

 

 

 

Thanks,

Divya 

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi  @iamnjain 

 

I am able to resolve this issue by adapting to SlingHttpServletRequest.class instead of Resource.class and added ComponentExporter.class and removed custom interface in adapters. I have added getter at class level.

Thank you for all your inputs.

Divya_13_0-1685622445401.png

 

View solution in original post

8 Replies

Avatar

Community Advisor

Hello @Divya_13 

 

Can you please try to tweak your main component sling model code a bit, as below

In your Model Interface, extends it with ComponentExporter class from 

com.adobe.cq.export.json.ComponentExporter
 
and In you Model impl class, apart from CapabilityMapModel interface in adapters, add 
ComponentExporter as well, like below

adapters = { CapabilityMapModel.class,
ComponentExporter.class }

Do let me know, if it's resolve your issue.

Avatar

Level 2

Hi @iamnjain 

 

When I added both adapters, ComponentExporter.class and CapabilityMapModel.class, the first level values are also coming empty in page model.json.

Avatar

Community Advisor

Hello @Divya_13 

 

I just now observed in your main sling model Impl class, you are using @JsonIgnore annotation on all three child resources ( multifields ), so that's the reason It's not appearing in your page json. Can you please try removing that annotation and build and see if it works?

Avatar

Level 2

Hi @iamnjain 

 

I have created a json array object(offices) and added all three child resources into the array and wanted to export this custom json object to page model json. So, I have added @JsonIgnore on other child resources and in the PostConstruct method I have set the property for the json obj.

Divya_13_0-1685616767635.png

 

Avatar

Community Advisor

Okay @Divya_13 Got It now!

Can you please try writing a explicit getter method for this json array object(offices) and try?

 

This seems interesting issue

Avatar

Correct answer by
Level 2

Hi  @iamnjain 

 

I am able to resolve this issue by adapting to SlingHttpServletRequest.class instead of Resource.class and added ComponentExporter.class and removed custom interface in adapters. I have added getter at class level.

Thank you for all your inputs.

Divya_13_0-1685622445401.png

 

Avatar

Community Advisor

Ohh, I didn't noticed that in first glance.

Anyways thanks for letting me know and glad It's resolved for you!

Avatar

Community Advisor

@Divya_13 can you add your solution a bit more clear as a separate reply so that we can get it marked as correct solution to this post?

 

@kautuk_sahni