Please Please Help me I want to store array JSON to Redis server Need Help Please
http://localhost:8585/api/redishome/redisGetBestTrainerBasedRating/101
response
{"message": "class java.util.ArrayList cannot be cast to class com.mycareerbuild.user.domain.BestTrainerBasedRating (java.util.ArrayList is in module java.base of loader 'bootstrap'; com.mycareerbuild.user.domain.BestTrainerBasedRating is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @5e243bf4)"}
I am able to store this below response without Making List
{"trainerid": 28,"rating": 5.0,"trainerName": "yellow","courseName": "","price": 0.0,"image": "null","language": "kannada"}
But I want to store it like this below when I try to make in with Listgetting above error response
[{"trainerid": 28,"rating": 5.0,"trainerName": "yellow","courseName": "","price": 0.0,"image": "null","language": "kannada"},{"trainerid": 28,"rating": 5.0,"trainerName": "yellow","courseName": "","price": 0.0,"image": "null","language": "telugu"},{"trainerid": 28,"rating": 5.0,"trainerName": "yellow","courseName": "","price": 6.0,"image": "null","language": "kannada"},{"trainerid": 28,"rating": 5.0,"trainerName": "yellow","courseName": "","price": 6.0,"image": "null","language": "telugu"},{"trainerid": 28,"rating": 5.0,"trainerName": "yellow","courseName": "","price": 10.0,"image": "null","language": "kannada"},{"trainerid": 28,"rating": 5.0,"trainerName": "yellow","courseName": "","price": 10.0,"image": "null","language": "telugu"}
]
My controller
@PutMapping("/redisGetBestTrainerBasedRating/{trainerid}")@ResponseBodypublic ResponseEntity<List<BestTrainerBasedRating>> redisGetBestTrainerBasedRating(@RequestBody List<BestTrainerBasedRating> item,@PathVariable Long trainerid) throws JsonProcessingException { List<BestTrainerBasedRating> ans = hc.redisGetBestTrainerBasedRating(item, trainerid); return new ResponseEntity<List<BestTrainerBasedRating>> (ans, HttpStatus.OK);}Component :@CachePut(value = "homeCache", key = "#trainerid", condition = "#result!= null")public List<BestTrainerBasedRating> redisGetBestTrainerBasedRating(List<BestTrainerBasedRating> item, Long trainerid) { System.out.println("In redisGetBestTrainerBasedRating cache Component.."); // item.setAnswer(item.getAnswer()); List<BestTrainerBasedRating> ans = cacheRepo.redisGetBestTrainerBasedRating(item, trainerid); return ans; // "Answer Submiteed with questionId "+questionId;}
Redis store code
public List<BestTrainerBasedRating> redisGetBestTrainerBasedRating(List<BestTrainerBasedRating> item, Long trainerid) { System.out.println("Geeting data from redis"+((BestTrainerBasedRating) item).getTrainerid()); hashOperations.put(KEY,((BestTrainerBasedRating) item).getTrainerid(),item); return item; }