bubka85
bubka85

Reputation: 59

how to fix a response entity object returning null in its body

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

Answers (1)

Dejan
Dejan

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

Related Questions