I have an Endpoint written in Java WS. The DTO classes used are as follows:
public class MainResponseDTO extends PaginationResponseDTO {
private List<MainDTO> mainDTOs;
public List<MainDTO> getMainDTOs() {
return mainDTOs;
}
public void setMainDTOs(List<MainDTO> mainDTOs) {
this.mainDTOs = mainDTOs;
}
}
And this class extends a PaginationResponseDTO
public class PaginationResponseDTO {
private int page;
private int limit;
private long size;
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
}
This is how I am sending responses.
@POST
@Path("/demo")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getExpiredAndDueDocumentsWithPagination() {
MainResponseDTO response = new MainResponseDTO();
// Used this for diagnosis
logger.debug(new Gson().toJson(response));
return Response.ok().entity(response).build();
}
However, the response on accesing the above URL (via Postman or Curl) gives the following response:
{
"type": "mainResponseDTO",
"limit": 0,
"page": 0,
"size": 0
}
I have not used a "type" property in any one of the DTOs then how is it getting appended. I also logged the JSON String representation of the response DTO using GSON just before returning the response which is as follows.
{"page":0,"limit":0,"size":0}
How did the "type" property get inside the response? Where have I gone wrong in my approach?
If the details provided in the question are insufficient do let me know for additional ones that are required.