Skip to content
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

Support both filters and views in AbstractJackson2HttpMessageConverter [SPR-17209] #21742

Closed
spring-projects-issues opened this issue Aug 23, 2018 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Aug 23, 2018

Daniel Raniz Raneland opened SPR-17209 and commented

Currently, if you set a view class on the MappingJacksonValue it will pick that and ignore any filter provider.

Both of these could be supported by changing:

ObjectWriter objectWriter;
if (serializationView != null) {
	objectWriter = this.objectMapper.writerWithView(serializationView);
}
else if (filters != null) {
	objectWriter = this.objectMapper.writer(filters);
}
else {
	objectWriter = this.objectMapper.writer();
}
if (javaType != null && javaType.isContainerType()) {
	objectWriter = objectWriter.forType(javaType);
}

into

ObjectWriter objectWriter = this.objectMapper.writer();
if (filters != null) {
    objectWriter = objectWriter.with(filters);
}
if (serializationView != null) {
    objectWriter = objectWriter.withView(serializationView);
}
if (javaType != null && javaType.isContainerType()) {
    objectWriter = objectWriter.forType(javaType);
}

We're using version 4.3.17, but as far as I can tell (by looking at GitHub) this is still the case for 5.0.


Affects: 4.3.17

Issue Links:

Referenced from: pull request #1940, and commits a44fe4c, 03f1920, 069704f

Backported to: 4.3.19

@spring-projects-issues
Copy link
Collaborator Author

Daniel Raniz Raneland commented

PR: #1940

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I've rolled this into master now in a slightly extended revision, consistently using writerWithView like in our other Jackson converters but applying a filter thereafter. This is consistent between AbstractJackson2HttpMessageConverter and AbstractJackson2View.

@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.0.9 milestone 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: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants