-1

When returning the response from controller in ResponseEntity for class B. But it returns empty json response. controller method is below:

 @PostMapping("/test")
    public ResponseEntity testSave(@Valid @RequestBody ReqData req, BindingResult result)
    {
        B response;
        if(result.hasErrors())
        {
            response=generateBadRequestResponse(result);//response variable of B type holds value in its fields, but not sending in response
            return ResponseEntity.ok(response); //getting empty json in postman response
        }

 
        return  ResponseEntity.ok(response);
    }

Whereas Class B is declared like this:

public class B <T> implements Serializable {

    private String message;
    private T body;
    private List<T> errorList= new ArrayList<>();
   
    //omitted unnecessary code for brevity
}

I tested the api from postman.

user404
  • 1,934
  • 1
  • 16
  • 32

1 Answers1

0

We need more details, a few scenarios it can happen:

  1. generateBadRequestResponse returns null
  2. no getters on B
KafKafOwn
  • 476
  • 2
  • 7
  • for no.1 , it is okay. 2 is on the point. I was setting value from the constructor and hence, getter setters were omitted, now works fine – user404 Jan 26 '22 at 15:07
  • Don't answer unclear questions; flag them for closure instead. – pppery Jan 26 '22 at 23:12