How to get each item of multifield in the form of json | Community
Skip to main content
New Participant
July 13, 2023
Solved

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

  • July 13, 2023
  • 3 replies
  • 1255 views

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

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 Suraj_Kamdi

Use the following code snippet.

 

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

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

3 replies

Anudeep_Garnepudi
New Participant
July 29, 2023

@anamikap 

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

String jsonStr = gson.toJson(valueMapObj)
New Participant
July 13, 2023

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

 

Suraj_Kamdi
Suraj_KamdiAccepted solution
New Participant
July 13, 2023

Use the following code snippet.

 

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

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