Skip to content

support nested property filters #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
krishna81m opened this issue Nov 17, 2015 · 5 comments
Closed

support nested property filters #230

krishna81m opened this issue Nov 17, 2015 · 5 comments

Comments

@krishna81m
Copy link

Problem: If there is a class say Person

class Person {
   string name;
   int age;
   Address address;

   .. getters and setters
}

How do we dynamically filter specific nested properties: name, address.state, address.zipcode reusing the same object mapper/writer.

One way is to follow the Spring integration to use property filter https://jira.spring.io/browse/SPR-12586. However, nested property filters are not supported. This is because of the way Jackson integration works. This is a very common use case to get only the fields clients are interested in runtime.

There are a few implementations already available that are slow because they lookup the jgen root context to build the nested path every time a property is checked if it can be filtered. These implementations also won't work without explicitly adding JsonFilter annotation on all classes that will be filtered:
https://github.com/PressAssociation/partial-response/tree/master/filter-json-jackson
https://github.com/Antibrumm/jackson-antpathfilter
https://github.com/narusas/SpringMvcJacksonFilter

The following won't work without @jsonfilter("antPathFilter") on all classes

objectMapper.addMixIn(Object.class, AntPathFilterMixin.class);
filter = new SimpleFilterProvider()
            .addFilter("antPathFilter",
                    new AntPathPropertyFilter("nestedObj", "nestedObj.nestedProperty")
jacksonValue.setFilters(filter);

One work around is to explicitly set the same @jsonfilter("antPathFilter") on all classes that are nested, which did not make any sense to me. What if I wanted to support multiple filters at the same time tomorrow?

I also ended up writing my own implementation that is fast and that uses SimplePropertyFilter per class built on the nested properties.

The problem really is the way Jackson APIs requests a filter for current property without any context on the current class owning that property.

https://github.com/krishna81m/jackson-nested-prop-filter

@krishna81m
Copy link
Author

Related ticket: https://jira.spring.io/browse/SPR-13622

@krishna81m krishna81m changed the title support nested property filters using Jackson support nested property filters Nov 17, 2015
@cowtowncoder
Copy link
Member

This issue does not belong here as filters are implemented by jackson-databind; jackson-core only implements streaming JsonParser, and not databind level property filtering.
You may want to refile this for jackson-databind, along with bit more detail on what changes you would want to see, from perspective of how the filter association should behave.

@krishna81m
Copy link
Author

Makes sense, closing this ticket to create one for jackson-databind

@heruan
Copy link

heruan commented Feb 29, 2016

@manojkr001
Copy link

manojkr001 commented Aug 22, 2020

It has been a long time since this above question has raised. Any update on support of nested object property filters using Jackson @jsonfilter. @cowtowncoder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants