Jersey Jackson data entity filtering JsonMappingException on collection

前端 未结 2 940
一个人的身影
一个人的身影 2021-02-09 06:50

I have an issue when trying to put in place the “selectable entity filtering”. I have an Abstract class like following one:

   // In your Pom
    

        
2条回答
  •  Happy的楠姐
    2021-02-09 07:46

    I am using SecurityEntityFilteringFeature, and I ran upon the same error.

    StdSerializer.findPropertyFilter.getFilterProvider and StdSerializer.findPropertyFilter are returning null.

    My solution is:

    @Provider
    public class JsonMappingExceptionOnCollectionResponseFilter implements ContainerResponseFilter {
    @Override
    public void filter(ContainerRequestContext requestCtx, ContainerResponseContext responseCtx) throws IOException {
        ObjectWriterInjector.set(new ObjectWriterModifier() {
    
            @Override
            public ObjectWriter modify(EndpointConfigBase endpoint, MultivaluedMap responseHeaders, Object valueToWrite, ObjectWriter w, JsonGenerator g) throws IOException {
                SimpleFilterProvider filterProvider = new SimpleFilterProvider();
                SimpleBeanPropertyFilter simpleBeanPropertyFilter = new SimpleBeanPropertyFilter() {
                    @Override
                    protected boolean include(BeanPropertyWriter writer) {
                        return true;
                    }
    
                    @Override
                    protected boolean include(PropertyWriter writer) {
                        return true;
                    }
                };
                filterProvider.addFilter("your entity class", simpleBeanPropertyFilter);
                filterProvider.addFilter("your entity class", simpleBeanPropertyFilter);
                return w.with(filterProvider);
            }
        });
    }
    

    }

提交回复
热议问题