jersey
jersey copied to clipboard
JsonMappingException when EntityFilteringFeature used with JacksonFeature
Using jersey-container-servlet 2.25 and jersey-media-json-jackson 2.25 (which uses jackson 2.8.4).
The application ResourceConfig includes:
// 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:
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 :-)
The key to reproducing this is "Can not resolve PropertyFilter with id 'java.util.LinkedHashMap'". There seems to be a problem serializing Java Map collections with EintityFiltering. I logged some additional detail here: https://github.com/jersey/jersey/issues/3732
And also, while your workaround prevents the exception from being thrown, it also seems to disable the SelectableEntityFilteringFeature/EntityFilteringFeature completely.
same issue here :( please fix it!