JFilter library could be used in Spring Web Service project for the filter(exclude) of fields in Service response. When you used Jackson @JsonView interface and need more powerful and flexibility, this library could be useful. For information please follow the links below.
Article in medium.com
Article in dzone.com
You can view all samples in GitHub Samples
For using this library you need to import dependency
<dependency>
<groupId>com.github.rkonovalov</groupId>
<artifactId>jfilter</artifactId>
<version>1.0.18</version>
</dependency>
- Attention: if you have used previous versions of library please rename artifactId from json-ignore to jfilter
If you need to add SOAP Web Services support you need to import SOAP dependency also
<dependency>
<groupId>com.github.rkonovalov</groupId>
<artifactId>jfilter-soap</artifactId>
<version>1.0.18</version>
</dependency>
Link to project JFilter Soap
For activation of JFilter library just add next annotation
@EnableJsonFilter
This example illustrates how easy you can configure Service Response. Just add FieldFilterSetting annotation with filterable fields and library 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
}
}
}
* Added ability of using DynamicFilter along with FilterSettings, Case #16
* Added ability of using DynamicFilter on class level, Case #18
* Added support of SOAP Web Services (alpha version)
* Added ability of using custom Message Converters, Case #11
* Added ability of change configuration of exist ObjectMappers, Case #11
* Removed of using ConverterMapperModifier, instead module uses MixinFilter for field filtering.
It's need for correct filtering of Java 8 types Case #12
* Simplified setting FilterFields into session or request attibutes for using DynamicSessionFilter
* Changed artifactId of project from json-ignore to jfilter
* Added ability of using default Spring MessageConverters MappingJackson2HttpMessageConverter and MappingJackson2XmlHttpMessageConverter instead of FilterConverter
* Added FilterXmlMapper and FilterObjectMapper for overriding default ObjectMapper and XmlMapper when using default Spring MessageConverters
* Changed generic type from Serializable to Object in FilterConverter
* Refactored FilterConverter class for inheriting AbstractHttpMessageConverter instead of HttpMessageConverter
* Added Comparator class for simplify if...else branching. Including in dynamic filter components
* Refactored DynamicSessionFilter component
* Fixed bug with LocalDateTime serializing
* Added ObjectMapperCache for caching of ObjectMapper from each method in Spring controller
* Added FilterConfiguration for extending of exist list of ObjectMappers and enabling/disabling of module
* Refactored code mechanizm of serializing Spring http messages
* Added HttpServletRequest in RequestSession for using in DynamicFilterComponent Case #6
* Added FilterBehaviour for keep/hide filtering fields Case #7
* Fixed bug in integration with Swagger UI Case #3
* Fixed bug "No converter found for return value of type" Case #1
* Added little features from Case #4, Case #5
* 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