Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

How to get each item of multifield in the form of json

Avatar

Level 1

I need each item of multifield as a json object in sling model. 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Use the following code snippet.

 

@ValuemapValue
private Collection<Pojo> multifieldResourceName = Collections.emptyList();

//logic goes here
ObjectMapper mapper = new ObjectMapper();
mapper.writeValueAsString(multifieldResourceName );

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Use the following code snippet.

 

@ValuemapValue
private Collection<Pojo> multifieldResourceName = Collections.emptyList();

//logic goes here
ObjectMapper mapper = new ObjectMapper();
mapper.writeValueAsString(multifieldResourceName );

Avatar

Level 2

hi @AnamikaP ,

Hope you have already found the answer for the above question. There are multiple ways to fetch Json Object. Below is one of the options

 

Avatar

Community Advisor

@AnamikaP 

Get each multifiled item ValueMap and use Gson to conver ValueMap to JSON.

String jsonStr = gson.toJson(valueMapObj)