1

From my service I am generating the JSON based on the language.I need to covert the array to the map which contains one value as key and another as value (lot of value in the arrays based on the database).

I have written the code I am getting the array and only "I need to convert into the list of key value pair like the given sample and write in the text file.

JSON from my service

[
[
    "task",
    "Comments"
],
[
    "CUSTOM_43_01",
    "Email"
],
[
    "CUSTOM_44_02",
    "Mobile"
],..........
]

1 Answers1

1

Try to convert your result from repository to expected result in the service like bellow:

public Map<String,String> getAllLangaugeDataForEn(Integer appId, String language) {
  Map<String,String> result = new HashMap();
  if (language.equalsIgnoreCase("EN")) {
   result  = languageRepository.getEnLanguageList(appId)
            .stream()
            .map(language-> new AbstractMap.SimpleEntry<>(language.getX(),language.getY()))
            .collect(Collectors.toMap(Map.Entry::getKey,Map.Entry::getValue));
   }
     return result;
}

language.getX() and language.getY() are LanguageDTO getters methods(LanguageDTO properties)!

Hadi J
  • 16,989
  • 4
  • 36
  • 62