Skip to content

support nested property filters using Jackson [SPR-13622] #18200

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
spring-projects-issues opened this issue Oct 29, 2015 · 4 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 29, 2015

rk opened SPR-13622 and commented

#17187 already supports filters but the underlying code does not filter nested properties because of the way Jakson and its spring integration works, there should be a custom filter to support simple nested property filtering (without any regular expressions). This is a very common use case to get only the fields clients are interested in runtime.

There are a few complex implementations already available, but these are not compatible with MappingJacksonValue as a drop in replacement, i.e., we cannot set their Filter implementations to MappingJacksonValue and expect them to 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 hack 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?


No further details from SPR-13622

@spring-projects-issues
Copy link
Collaborator Author

rk commented

Ended up writing a workaround that uses SimplePropertyFilter per class built on the nested properties. The problem is apparently the way Jackson APIs requests a filter for the current property without any context on the current class owning that property. Will file a ticket with Jackson.

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

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

I also feel that this should be improved as Jackson level rather than at Spring level.
Could you please post here the link of the Jackson issue when it will be created?

@spring-projects-issues
Copy link
Collaborator Author

rk commented

Related ticket: FasterXML/jackson-core#230

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

This issue has been discussed on Jackson side.

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants