You do not need to use Jackson to do this. Just filter it using Stream API. If data, are loaded from DB, filter it using SQL's WHERE clause.
Example:
@GetMapping(value = "/states", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<MyObject> loadStates(@RequestParam(name = "state", defaultValue = "NY", required = false) String[] states) {
return service.loadAndFilterByState(states);
}
If you have a cached list, you can filter it like below:
@GetMapping(value = "/states", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<MyObject> loadStates(@RequestParam(name = "state", defaultValue = "NY", required = false) String[] states) {
Arrays.sort(states);
return getStates()
.stream()
.filter(s -> Arrays.binarySearch(states, s.getState()) > -1)
.collect(Collectors.toList());
}
See also: