Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

count datas in three repositories and put them in a list or a map and convert it to json

I have three lists that holds the number of data in a database

List<Long> list1= list1Repo.countAll();
List<Long> list2= list2Repo.countAll();
List<Long> list3= list3Repo.countAll();

I want to combine these lists into one JSON object which supposed to be as follows:

[
  { label: "list1", value: 30 },
  { label: "list2", value: 25 },
  { label: "list3", value: 25 },
 
]

value is the counted numbers inside the lists.
How do i do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Store your data like this in a Map:

Map<String, Long> listCountMap = new HashMap<>();
listCountMap.put("list1", list1Repo.countAll());
listCountMap.put("list2", list2Repo.countAll());
listCountMap.put("list3", list3Repo.countAll());

Then refer to this answer to convert your map into a JSON object.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading