Response entity return header in the response

609 Views Asked by At

I'm returning a list of error messages using a ResponseEnitiy body method. Altough I'm not sure why it's returning header object on the top of the reponse Ex:

[
{
    "headers": {},
    "body": {
        "code": 6,
        "description": "Billing account must not be null!.",
        "tcn": "c6fcaa15-bc68-4dc9-87b8-2722ea3e6a20",
        "personId": "1087280192",
        "errorDetails": null,
        "billingAccountsDTO": {
            "billingAccountNumber": "",
            "debtAmount": 1000.0,
            "msisdn": "0554160163",
            "hasProblem": true
        }
    },
    "statusCode": "BAD_REQUEST",
    "statusCodeValue": 400
},
{
    "headers": {},
    "body": {
        "code": 8,
        "description": "Msisnd must not be invalid or null!.",
        "tcn": "c6fcaa15-bc68-4dc9-87b8-2722ea3e6a20",
        "personId": "1087280192",
        "errorDetails": null,
        "billingAccountsDTO": {
            "billingAccountNumber": "STC234562",
            "debtAmount": 0.0,
            "msisdn": "05541x60163",
            "hasProblem": true
        }
    },
    "statusCode": "BAD_REQUEST",
    "statusCodeValue": 400
}

]

I want to get rid of the heasers object. The wierd behavour is that when I'm not returning a list of responses. the headers dissapeare !!!

napshot of the implementation of the response :

Response buildResponse(String tcn, ResponseCode responseCode, String personId, BillingAccountsDTO billingAccount) {
Response response =
    new Response(responseCode.getCode(), responseCode.getDescription(), tcn, personId, billingAccount,null);
return response;

}

   response = ResponseEntity.status(HttpStatus.BAD_REQUEST)
                .body(buildResponse(tcn, ResponseCode.INVALID_DEBT_AMOUNT, billingAccountDTO.getPersonId(), billingAccountsDTO));
        auditLog.setRequestBody(billingAccountDTO.toString());
        auditLog.setResponseCode(ResponseCode.INVALID_DEBT_AMOUNT.getCode());
        billingAccountsDTO.setHasProblem(true);
        responseList.add(response);
      }
0

There are 0 best solutions below