I want to use this code to get some data from Rest API:
public Map<Integer, String> getCategoriesList() {
Map<Integer, String> list = new HashMap<>();
list.put(1, "Electronics");
list.put(2, "Outdoor and Sports");
list.put(3, "Home and Garden");
list.put(4, "Home appliances");
list.put(5, "Air conditioners and heaters");
list.put(6, "IT accessories");
list.put(7, "Photo and Video");
list.put(8, "TV Video and Gaming");
return list;
}
@GetMapping("categories")
public ResponseEntity<List<String>> getCategoriesList() {
return (ResponseEntity<List<String>>) categoriesService.getCategoriesList();
}
I get error: class java.util.HashMap cannot be cast to class org.springframework.http.ResponseEntity
What is the appropriate way to return this data as a response?