-
Notifications
You must be signed in to change notification settings - Fork 37.7k
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
Allow @JsonSerialize to be used on @Controller methods [SPR-13369] #17953
Comments
Sébastien Deleuze commented That would be indeed useful, but I am not sure Jackson API allows us to specify a We currently use That makes me think that even if you can annotate POJOs with Any thoughts ? |
Phil Webb commented Perhaps a custom |
Dmitry F. commented it would be best future |
Jon Edvardsson commented I am looking for the same feature. Infact, I think it can be done quite easily by just some minor tweaks of the existing code. Consider that we add support for JsonSerialize.as, then we need to add a field writerFor in MappingJacksonValue. We need to create a new class JsonSerializeResponseBodyAdvice similar to the JsonViewResponseBodyAdvice that copies this info over to MappingJacksonValue. Then finally update the AbstractJackson2HttpMessageConverter#writeInternal to: // ... code left out before
ObjectWriter objectWriter;
if (filters != null) {
objectWriter = this.objectMapper.writer(filters);
}
else if (writerFor != null) {
objectWriter = this.objectMapper.writerFor(writerFor);
}
else if (javaType != null && javaType.isContainerType()) {
objectWriter = objectWriter.withType(javaType);
else {
objectWriter = this.objectMapper.writer();
}
if (serializationView != null) {
objectWriter = objectWriter.withView(serializationView);
}
objectWriter.writeValue(generator, value);
//... code left out after |
Bulk closing outdated, unresolved issues. Please, reopen if still relevant. |
Phil Webb opened SPR-13369 and commented
Similar to the
@JsonView
support it would be helpful if the@JsonSerialize
annotation could be used on a@Controller
method.Possibly raised before in #13935
Issue Links:
@JsonSerialize
) when returning objects from methods annotated with@ResponseBody
The text was updated successfully, but these errors were encountered: