I"m currently building a React/Springboot application and my goal is to return single object from the Array but objects are not valid in react, Does anyone know how to I could pull the data from the object inside JSON Array or if there is a method I could put in my controller that would format the objects inside the array as mini arrays?
{
- drinks: {
id: 1,
drinkId: null,
drinkName: "Bloody Mary",
glassType: "Highball",
strAlcoholic: "Alcoholic",
drinkDetails: "A Bloody Mary is a cocktail containing vodka, tomato juice, and other
spices and flavorings including Worcestershire sauce, hot sauces, garlic, herbs,
horseradish, celery, olives, salt, black pepper, lemon juice, lime juice and celery
salt.",
720x720-primary-28cf1aaa79d0424d951901fcc0a42e91_xmhgw9.jpg"
}
}
Here is my Controller for the above json data:
@GetMapping(path = "all/{id}")
@CrossOrigin
public @ResponseBody Map<String, Optional<Drink>> getById(@PathVariable Long id){
Map<String, Optional<Drink>> response = new HashMap<>();
response.put("drinks", drinkRepository.findById(id));
return response;
}