method count(JobViewWrapper) is already defined

If you really want to overload method count you must select one of the three options available:

  1. provide different number of parameters:
@PostMapping(value = "/count")
public long count(@RequestBody(required = false) JobViewWrapper wrapper) {
// ...
    return JobService.countLazyView();
}

@PostMapping(value = "/count-active")
public long count() {
    return JobService.countLazyViewIsActive();
}
  1. provide different types of parameters:
@PostMapping(value = "/count")
public long count(@RequestBody(required = false) JobViewWrapper wrapper) {
// ...
    return JobService.countLazyView();
}

@PostMapping(value = "/count-active")
public long count(@RequestBody(required = false) ActiveJobViewWrapper wrapper) {
    return JobService.countLazyViewIsActive();
}
  1. provide different order of parameters (seems to be not applicable in this case).

If none of these options can be selectable, you’ll have options:

  1. Provide different names for these methods count() and countActive

  2. Replace these methods with one method having additional parameter (API call may be changed to /count?active=true):

@PostMapping(value = "/count")
public long count(
    @RequestParam(name = "active", required = false, defaultValue = "false") Boolean active, 
    @RequestBody(required = false) JobViewWrapper wrapper) {
// ...
    
    return active ? JobService.countLazyViewIsActive() : JobService.countLazyView();
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top