How to send optional request parameters of an api request to another method/function

Viewed 40

I am trying to send both or one of the optional request parameters of my API to another calling method/ function. Can someone advice me on how, if that is possible please.

public ca.alea.cam.api.model.Response importStaticFile(@RequestBody(required = false) List<String> str, @RequestPart(required = false) MultipartFile file) throws Exception, ContentRepositoryDaoException {
...
// some code...
// I want to send str and/or file to another method
method_name(str,file);
...
}

Thanks

1 Answers
Just use java.util.Optional,

public ca.alea.cam.api.model.Response importStaticFile(@RequestBody(required = false) List<String> str, @RequestPart(required = false) Optional<MultipartFile> file) throws Exception, ContentRepositoryDaoException {
...
//you can check if it is present or not like below.
if(file.isPresent())
method_name(str,file);
...
}
Related