This module could be used in Spring Web Service project for filter(exclude) of fields in Service response. When you used Jackson @JsonView interface and need more powerful and flexibility, this module could be useful. For information please follow the links below.
Publication on medium.com
Publication on dzone.com
For using this module you need to import dependency
<dependency>
<groupId>com.github.rkonovalov</groupId>
<artifactId>json-ignore</artifactId>
<version>1.0.8</version>
</dependency>
For activation of JFilter module just add next annotations
- Component scan and enable filter
@ComponentScan({"com.jfilter.components"})
@EnableJsonFilter
This example illustrates how easy you can configure Service Response. Just add FieldFilterSetting annotation with filterable fields and module will exclude them from response
@FieldFilterSetting(className = User.class, fields = {"id", "password", "secretKey"})
@RequestMapping(value = "/users/signIn",
params = {"email", "password"}, method = RequestMethod.POST,
consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE})
public User signIn(@RequestParam("email") String email, @RequestParam("password") String password) {
return userController.signInUser(email, password);
}
- Service response before filtration
{
"id": 10,
"email": "[email protected]",
"fullName": "Jane Doe",
"password": "12345",
"secretKey": "54321",
"address": {
"id": 15,
"apartmentNumber": 22,
"street": {
"id": 155,
"streetName": "Bourbon Street",
"streetNumber": 15
}
}
}
- Service response after filtration
{
"email": "[email protected]",
"fullName": "Jane Doe",
"address": {
"id": 15,
"apartmentNumber": 22,
"street": {
"id": 155,
"streetName": "Bourbon Street",
"streetNumber": 15
}
}
}
For more examples please follow to the link Examples
* Added Dynamic Filter which allows to create own filters with custom behaviour
* Added DynamicSessionFilter for storing custom field filter in session
* Added feature for auto loading XML Schema-based configuration filter when it changed on runtime
* Changed package name from com.json.ignore to com.jfilter
* Changed package from advice to components
* Fixed bug in FileFilter which not allowed to load xml configuration from external source
* Added FileWatcher controller which auto reloads modified XML Schema based configurations
* Refactored Javadoc
* Fixed incorrect Jackson XML dependency importing
* Added JSON/XML converters inherited from HttpMessageConverter
* Removed native reflection and added Jackson BeanSerializerModifier for field filtering
* Added EnableJsonFilter annotation for enabling/disabling filtration
* Added ability to apply filter annotations on whole Spring Rest controller
* Fixed bugs
* Added Filter provider for improving execution speed
* Fixed bugs
* Added xml Schema-based configuration
* Fixed bugs
* Added session strategy filtering
* Added additional constructors
* Initial release