I need each item of multifield as a json object in sling model.
Solved! Go to Solution.
Use the following code snippet.
@ValuemapValue
private Collection<Pojo> multifieldResourceName = Collections.emptyList();
//logic goes here
ObjectMapper mapper = new ObjectMapper();
mapper.writeValueAsString(multifieldResourceName );
Use the following code snippet.
@ValuemapValue
private Collection<Pojo> multifieldResourceName = Collections.emptyList();
//logic goes here
ObjectMapper mapper = new ObjectMapper();
mapper.writeValueAsString(multifieldResourceName );
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
Once you have the object (SocialLinkModel) in the above example, you can get the Json using Gson Library or Jackson API
example : https://www.javatpoint.com/convert-java-object-to-json
Get each multifiled item ValueMap and use Gson to conver ValueMap to JSON.
String jsonStr = gson.toJson(valueMapObj)
Views
Likes
Replies
Views
Likes
Replies