Sling Model usage for property of type string Array in AEM 6.3 | Community
Skip to main content
cquser1
Level 7
July 13, 2017
Solved

Sling Model usage for property of type string Array in AEM 6.3

  • July 13, 2017
  • 5 replies
  • 5024 views

Hi,

Suppose, I have a pathbrowser within multifield. For instance I select two paths in dialog, which is stored in backend as {"pagePath":"/content/test1"}, {"pagePath":"/content/test2"}. I want to retrieve the jcr: title of these two pages. How do I go about doing this.

If I were to use, WCMUsePOJO's/activate method, I would have done something like

ValueMap properties = getProperties();

if (properties.containsKey("multifieldPropertystoredincrx")) {

String[] paths= properties.get("multifieldPropertystoredincrx", String[].class);

for (int i = 0; (null != paths) && (i < paths.length); i++) {

JSONObject obj = new JSONObject(paths[i]);

if (obj.has("pagePath")) {

String productPath = obj.getString("pagePath"));

and so on.

But with SlingModel, I am not getting how to go about this. Any thoughts on this will be really helpful.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by zeeshanKhan0786

Hi

Use some other API.. jackson and gson can be used here. I believe both are available with AEM 6.3

Java POJO to JSON using Gson (com.google.gson.Gson) - CoderMagnet - JAVA JCR AEM Sightly Resource

5 replies

zeeshanKhan0786
Level 5
July 13, 2017

You can follow this link hope you will get the idea.

Multifield Component in Sightly with Sling Models | TechCookies

cquser1
cquser1Author
Level 7
July 14, 2017

Hi zeeshank15007365,

Thanks a lot for sharing this link across.

In AEM 6.3, JSONObject is deprecated and as a result , cannot proceed with the same.

Any link/pointers on how to achieve this without JSONObject api, would be helpful.

viveksachdeva
Community Advisor
Community Advisor
July 14, 2017

Use some other API.. jackson and gson can be used here. I believe both are available with AEM 6.3

cq5 - org.apache.sling.commons.json.JSONArray is deprecated in AEM 6.3 - Stack Overflow

zeeshanKhan0786
zeeshanKhan0786Accepted solution
Level 5
July 14, 2017

Hi

Use some other API.. jackson and gson can be used here. I believe both are available with AEM 6.3

Java POJO to JSON using Gson (com.google.gson.Gson) - CoderMagnet - JAVA JCR AEM Sightly Resource

cquser1
cquser1Author
Level 7
July 14, 2017

Thank you