Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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 3

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)