In a webservice developed in Spring Boot framework, I am looking for a way to filter few sensitive fields in the response. I am trying with JsonFilter. Here is the code I tried so far:
@ApiModel (value = "Customer")
@JsonInclude (JsonInclude.Include.NON_NULL)
@JsonFilter("CustomerFilter")
public class Customer implements Serializable
{
...
}
Controller code that sends filtered response:
MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(customer);
FilterProvider filters = new
SimpleFilterProvider().setFailOnUnknownId(false).addFilter("CustomerFilter",
SimpleBeanPropertyFilter.filterOutAllExcept("customerId"));
mappingJacksonValue.setFilters(filters);
return ResponseEntity.status(HttpStatus.OK).body(mappingJacksonValue);
While invoking the request, the following exception is thrown. com.fasterxml.jackson.databind.JsonMappingException: Can not resolve PropertyFilter with id 'CustomerFilter'; no FilterProvider configured
Am I missing any configuration?