Expand my Community achievements bar.

Join us in celebrating the outstanding achievement of our AEM Community Member of the Year!
SOLVED

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

Avatar

Level 8

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.

1 Accepted Solution

Avatar

Correct answer by
Level 5

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

View solution in original post

5 Replies

Avatar

Level 8

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.

Avatar

Community Advisor

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

Avatar

Correct answer by
Level 5

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