4

This worked at one point in Jackson. I want to apply a filter to objects in a Collection.

reponse.getOriginalResponse() -> Collection

mapper.writer(filterProvider).writeValueAsString(response.getOriginalResponse());

The filter is

this.filters.put("myfilter", SimpleBeanPropertyFilter
                .filterOutAllExcept("test"));

The resulting json in the string is the entire object instead of just an array of objects with one property called test...

I am not sure at what point this stopped working or if there was some other configuration that needs to be added to make it work in Jackson

Also tried

SimpleBeanPropertyFilter.serializeAllExcept("test")

There must be some new Trick to telling Jackson that the objects in the Collection are the type I want to filter.

EDIT: I tried it with just one object

MyObject i = ((List<MyObject>) response
                        .getOriginalResponse()).get(0);

                output = mapper.writer(filterProvider).writeValueAsString(i);

And it still output the entire object... filter was essentially ignored...

chrislhardin
  • 1,747
  • 1
  • 28
  • 44
  • 4
    This should work with latest Jackson. Make sure you have annotated the class to be serialized with `@JsonFilter("myFilter")` and that you have added the filter to `filterProvider` (you'd normally invoke `addFilter` on the provider) – Manos Nikolaidis Nov 18 '17 at 10:54
  • 1
    you nailed it... I forgot to annotate the object – chrislhardin Nov 18 '17 at 15:31

0 Answers0