jersey icon indicating copy to clipboard operation
jersey copied to clipboard

JsonMappingException when EntityFilteringFeature used with JacksonFeature

Open amichair opened this issue 7 years ago • 2 comments

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 :-)

amichair avatar Jun 06 '17 22:06 amichair

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.

crizo23 avatar Nov 22 '17 00:11 crizo23

same issue here :( please fix it!

xtermi2 avatar Mar 02 '18 09:03 xtermi2