0
votes

I Have a service method that returns a ResponseEntity<List<Attachment>> and its hystrix fallback method must also return a ResponseEntity<List<Attachment>>.
The problem is that I need to return a String message that clarifies the error to the user instead of returning a new Arraylist<>()

- Here is my method

@Override
@HystrixCommand(fallbackMethod = "getAttachmentsFallback")
public ResponseEntity<List<AttachmentDto>> getAttachments(IAttachable entity) {
    List<AttachmentDto> attachments = client.getAttachments(entity.getAttachableId(), entity.getClassName(),
            entity.getAppName());
    return new ResponseEntity<List<AttachmentDto>>(attachments, HttpStatus.OK);
}

And that's its fallback

public ResponseEntity<List<AttachmentDto>> getAttachmentsFallback(IAttachable entity, Throwable e) {
    //I need to return a String instead of the new Arraylist<AttachmentDto>() 
    return new ResponseEntity<List<AttachmentDto>>(new ArrayList<AttachmentDto>(), HttpStatus.INTERNAL_SERVER_ERROR);
}
2

2 Answers

2
votes

Just use :

ResponseEntity<Object>

this will work for any type. Because Object is the top most class defined in java.lang

instead of:

ResponseEntity<List<AttachmentDto>>
0
votes

I Made it work by doing ResponseEntity with no args instead of ResponseEntity<List<AttachmentDto>>

Thanks guys