Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

How to Export JSON (Business Logic) of multiple components in a page using Sling Model Exporter

Avatar

Avatar
Validate 1
Level 1
mayanky56670501
Level 1

Like

1 like

Total Posts

13 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
mayanky56670501
Level 1

Like

1 like

Total Posts

13 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
mayanky56670501
Level 1

05-12-2018

I am not able export JSON of multiple components in a page using Sling Model Exporter.

If I am using http://localhost:4502/content/test.model.json, then I am getting the simple json of the Page.

If I am using http://localhost:4502/content/test.infinity.json then I am getting the Deep level JSON for all the Node Content.

I basically want to get the JSON for my business logic developed in JAVA, that to be of multiple components lying on the page.

Using @Exporter Annotation. I am able to get the JSON for Individual Component, but I am not able to get that JSON for multiple components.

Would be grateful if anyone could provide the correct solution!

Replies

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,357 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,357 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

05-12-2018

Hi,

You can create exporter for multiple components but when you will access page using .model.json, it will return the JSON response from multiple components

Adobe Experience Manager Help | Understanding Sling Model Exporters in AEM

e.g.

http://localohost:4502/content/my-resource.model.json

Avatar

Avatar
Validate 1
Level 1
mayanky56670501
Level 1

Like

1 like

Total Posts

13 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
mayanky56670501
Level 1

Like

1 like

Total Posts

13 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
mayanky56670501
Level 1

05-12-2018

It will return only the JSON which is stored under the node /content/my-resource/jcr:content/...

But my question is how to Export the JSON of Multiple Components on a particular page that to be of a JAVA Based Logic, not the simple data which you put inside the Dialog.

Avatar

Avatar
Validate 1
Level 1
mayanky56670501
Level 1

Like

1 like

Total Posts

13 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
mayanky56670501
Level 1

Like

1 like

Total Posts

13 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
mayanky56670501
Level 1

05-12-2018

This is JCR Node Structure and via /content/my-page.infinity.json

I am getting a JSON basis of this Node Structure.

JCR Node Structure.PNG

JSON Structure on Node Basis!

JSON Sample.PNG

While on the other hand, a Sling Model Exporter JSON like..

Sling Model JSON.PNG

Just like this.. I want to Export the JSON for multiple components made using Sling Model @Exporter lying on the same page.. by simply calling /content/my-page.model.json or something!!

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,357 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,357 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

05-12-2018

Hi,

Did you try to access your page with model selector? Can you show the response.

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

05-12-2018

I am not sure this is a possible use case - as discussed in this How To article - JSON is exported based on a single component.

Adobe Experience Manager Help | Exporting Adobe Experience Manager Data Using Sling Model Exporters

If it is possible - i have never seen the code to do so.

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

05-12-2018

If you look at the Java code in this article - you will notice that data members of the code lineup with component props. So its binding components props to data members. For example:

@Model(adaptables = Resource.class, resourceType = { "weretail/components/content/heroimage" }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)

@Exporter(name = "jackson", extensions = "json", options = { @ExporterOption(name = "SerializationFeature.WRITE_DATES_AS_TIMESTAMPS", value = "true") })

public class ModelComponent {

    @Inject

    String title;

    @Inject

    String heading;

    @Inject

    String buttonLabel;

    @Inject

    String buttonLinkTo;

    @Inject

    String fileReference;

    @Inject

    @Named("sling:resourceType")

    String slingResourceType;

    public String getHeading() {

        return heading;

    }

    public String getButtonLabel() {

        return buttonLabel;

    }

    public String getButtonLinkTo() {

        return buttonLinkTo;

    }

    public String getSlingResourceType() {

        return slingResourceType;

    }

    public String getTitle() {

        return title;

    }

    public String getFileReference() {

        return fileReference;

    }

}

Therefore, unless you know the components and its props you want to export, this code will not work.

Avatar

Avatar
Validate 1
Level 1
mayanky56670501
Level 1

Like

1 like

Total Posts

13 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
mayanky56670501
Level 1

Like

1 like

Total Posts

13 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
mayanky56670501
Level 1

05-12-2018

So, is there any possible solution for that? or I need to write a Custom Sling Servlet only? I js wanted to know if there's any solution, otherwise the last possible solution is only to write a Custom Sling Servlet!!

Avatar

Avatar
Validate 1
Level 1
mayanky56670501
Level 1

Like

1 like

Total Posts

13 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
mayanky56670501
Level 1

Like

1 like

Total Posts

13 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
mayanky56670501
Level 1

05-12-2018

If I will make a Sling Model of Page Component, then it will only export the JSON of that page properties only. It will not work for the components lying under it.

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

05-12-2018

As you need to bind data members to component props - you cannot really use a Sling Model Exporter as shown in this article. It was really a 1-1 based on a given component. You may want to look at looking at components and reading the props you want and encoding to JSON.