Reputation: 59
How to fix a rest template object returning null in the body
ResponseEntity<List<Spot>> reEntity = new ResponseEntity<List<Spot>>(HttpStatus.OK);
ParameterizedTypeReference<List<Spot>> parameterizedTypeReference = new ParameterizedTypeReference<List<Spot>>() {
};
List<Spot> spots = new ArrayList<Spot>(); //initialized
resEntity.getBody().addAll(spots);//getBody() is returning null
Upvotes: 1
Views: 423
Reputation: 353
You should define the body on this line
ResponseEntity<List<Spot>> reEntity = new ResponseEntity<List<Spot>>(HttpStatus.OK);
like this next line
ResponseEntity<List<Spot>> reEntity = new ResponseEntity<List<Spot>>(spots, HttpStatus.OK);
I would even suggest you to use ResponseEntity builder like following
ResponseEntity.ok(spots);
Upvotes: 1