How to get each item of multifield in the form of json | Community
Skip to main content
Level 2
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

Suraj_Kamdi
Community Advisor
Suraj_KamdiCommunity AdvisorAccepted solution
Community Advisor
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 );
Level 4
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

 

Anudeep_Garnepudi
Community Advisor
Community Advisor
July 29, 2023

@anamikap 

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

String jsonStr = gson.toJson(valueMapObj)