I have an Operation service that has a list function that returns a list of OperationDTO however when the controller calls this function the list returns null dto objects and if I change the type of return in the service to Operation entity type the controller works fine
public class OperationDTO {
private Long user_id;
private Long account_id;
private int amount;
private TypeOperation typeOperation;
private boolean status;
private Date created;
private Date updated;
public OperationDTO(Operation operation){
this.user_id = operation.getUser().getId();
this.account_id = operation.getAccount().getId();
this.amount = operation.getAmount();
this.typeOperation = operation.getTypeOperation();
this.status = operation.isStatus();
this.created = operation.getCreated();
this.updated = operation.getUpdated();
}
public OperationDTO(){}
@Override
public String toString() {
return this.user_id + " "+
this.account_id + " "+
this.typeOperation + " "+
this.amount+ " "+
this.status+ " "+
this.created+ " "+
this.updated
;
}
}
this is my implementation to my service
public Collection<OperationDTO> listOperation() {
Collection<Operation> operations = (Collection<Operation>)
operationRepository.findAll();
Collection<OperationDTO> operationDTOS = new ArrayList<>();
for (Operation oper: operations){
OperationDTO op = new OperationDTO(oper);
operationDTOS.add(op);
}
System.out.println("Les operations " + operationDTOS);
return operationDTOS;
}
My controller
public ResponseEntity<EntityResponse> list(){
return ResponseEntity.ok(
EntityResponse.builder()
.timeStamp(LocalDateTime.now())
.message("List of Operations" )
.status(HttpStatus.OK)
.statusCode(HttpStatus.OK.value())
.data(Map.of("Operation list", operationService.listOperation()))
.build()
);
}
When a call this list in my controller with postman I have this response
{
"timeStamp": [
2022,
5,
13,
20,
46,
57,
754770000
],
"statusCode": 200,
"status": "OK",
"message": "List of Operations",
"data": {
"Operation list": [
{},
{},
{}
]
}
}
please need some help