-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
@JsonView not working with @RestController [SPR-13331] #17916
Comments
Fabian Cernota commented If there a any questions please ask :) |
Rossen Stoyanchev commented This is likely related to #17408, which is partly an issue in Jackson (having to do with polymorphic collections) fixed in 2.6 and also required some additional code on the Spring side available in 4.2. If you are able to give it a try with Jackson 2.6 and Spring Framework 4.2 that would be helpful, thanks. |
Fabian Cernota commented I still get empty {} |
Sébastien Deleuze commented If you have empty {}, it may come from what is described in #17154. Could you have a look to #17154 comments related to setting |
Fabian Cernota commented I use your example: @EnableWebMvc
@Configuration
@ComponentScan(basePackages = { "de.example.project.rest" })
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
final static Logger log = LoggerFactory.getLogger(WebMvcConfiguration.class);
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
ObjectMapper mapper = Jackson2ObjectMapperBuilder.json().defaultViewInclusion(true).build();
converters.add(new MappingJackson2HttpMessageConverter(mapper));
log.info("Jackson Configured");
log.info(converters.toString());
}
} And on the console i get both log lines: INFO de.example.project.utils.WebMvcConfiguration - Jackson Configured
INFO de.example.project.utils.WebMvcConfiguration - [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@5b4e8073] When i called the REST-service i get Still empty brackets an on console i get a message like DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor - Written [org.springframework.http.converter.json.MappingJacksonValue@583a424b] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@39a4125b] Any ideas? Thanks |
Sébastien Deleuze commented I have tried to reproduce your issue by updating https://github.com/sdeleuze/SpringSampleProject, but it seems to work as expected with Spring 4.1.6 and 4.2.0 (even when returning Could you provide a small sample project that allows to reproduce the issue? |
Fabian Cernota commented Here is a simple Spring sample project were i can reproduce the problem: |
Sébastien Deleuze commented Thanks for creating a repro project. The root cause of the problem you have is that you have both XML and JavaConfig configuration in your application. I have created a pull request that fixes your application, but removing the XML based Spring MVC configuration (and other small fixes). With these changes, it seems to work as expected. |
Fabian Cernota opened SPR-13331 and commented
Hi,
i use Spring 4.1.6 with Jackson 2.5.1 and i want to customize my json output using
@jsonview
annotation.I have a Entity Like
Define my views as follows
JPA Repository:
And RestController:
In my browser i only see empty brackets {}. When i doesn't use JSONViews it shows me everything from the entities.
Thanks
Fabian
Affects: 4.1.6
The text was updated successfully, but these errors were encountered: