eclipse-ee4j / eclipse-ee4j/jersey
JsonMappingException when EntityFilteringFeature used with JacksonFeature
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Using jersey-container-servlet 2.25 and jersey-media-json-jackson 2.25 (which uses jackson 2.8.4).
The application ResourceConfig includes:
```java
// gzip support
register(EntityFilteringFeature.class);
EncodingFilter.enableFor(this, GZipEncoder.class);
// jackson serializer
register(JacksonFeature.class);
// application classes
packages("com.example");
```
if only one of JacksonFeature or EntityFilteringFeature is used, everything is ok. But when both are used together, Jackson serialization fails with
>JsonMappingException: Can not resolve PropertyFilter with id 'java.util.LinkedHashMap'; no FilterProvider configured
There are a few similar issues reported in e.g. stackoverflow, with very elaborate workarounds. The workaround I found is modifying the custom ObjectMapper used in the application to use a no-op filter:
```java
SimpleFilterProvider filterProvider = new SimpleFilterProvider();
filterProvider.setDefaultFilter(new SimpleBeanPropertyFilter.SerializeExceptFilter(Collections.emptySet()));
mapper.setFilterProvider(filterProvider);
```
So it seems like adding gzip support to a jersey+jackson application breaks the serialization.
I'm not 100% sure the issue is with Jersey rather than Jackson, but I reported this first at https://github.com/FasterXML/jackson-databind/issues/1645 and they pointed the finger at you :-)
Contributor guide
Research direction
Start with the ResourceConfig setup shown in the report, especially the interaction between EntityFilteringFeature, EncodingFilter, and JacksonFeature. Reproduce the JsonMappingException with both features enabled and compare serialization with each feature enabled alone; done means the combined configuration serializes successfully without requiring the reported custom ObjectMapper filter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100