question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support nested property filters

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
bohnmancommented, Apr 2, 2017

I wrote a library called Squiggly Filter, which selects fields based on a subset of the Facebook Graph API syntax. For example, to select the zipCode of the address field of the user object, you would use a filter address{zipCode}.

More information here

0reactions
cowtowncodercommented, Oct 5, 2016

I don’t think I know what should be done here; but I do note that some new functionality has been added in JsonParser; specifically, in Jackson 2.5, ability to set and get “current value” which is the POJO being read. This combined with parent stack of current property names should allow building nested filters. But I don’t see things to work on in Jackson proper itself at this point.

For new specific ideas, requests, feel free to file a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NestedFilters - Amazon SageMaker - AWS Documentation
A list of nested Filter objects. A resource must satisfy the conditions of all filters to be included in the results returned from...
Read more >
Filter nested Object property uisng @JsonFilter - Stack Overflow
I want to filter the properties of Employee and its nested object Address ... update on the support of nested object properties by...
Read more >
filtering collection of nested property - DevExpress Support
Hi, I have a situation where I want to filter collection of objects which contain again collection of other objects.
Read more >
nested-object-filter - npm
This package allows you to filter nested javascript object regardless how nested the object is. You specify an array of nested arrays to ......
Read more >
FilterChains and FilterReaders - Apache Ant
The class name of the filter reader. Yes. Nested elements. <filterreader> supports <classpath> and <param> as nested elements. Each ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found