@Bean
  public ContentNegotiatingViewResolver viewResolver() {

    ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();

    // Used strategy only for JSON
    FixedContentNegotiationStrategy fixedStrategy =
        new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON);
    Collection<ContentNegotiationStrategy> strategies = new ArrayList<ContentNegotiationStrategy>();
    strategies.add(fixedStrategy);
    resolver.setContentNegotiationManager(new ContentNegotiationManager(fixedStrategy));

    // Handle formatting of dates and JSON root elements
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
    mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.registerModule(new JodaModule());

    ArrayList<View> defaultViews = new ArrayList<View>();

    MappingJackson2JsonView jsonView = new MappingJackson2JsonView();
    jsonView.setObjectMapper(mapper);
    jsonView.setExtractValueFromSingleKeyModel(true);

    defaultViews.add(jsonView);
    resolver.setDefaultViews(defaultViews);

    resolver.setOrder(2);

    return resolver;
  }
  @Bean
  public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
    ContentNegotiationManagerFactoryBean contentNegotiationManager =
        new ContentNegotiationManagerFactoryBean();
    contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);

    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/views/");
    viewResolver.setSuffix(".jsp");

    MappingJackson2JsonView defaultView = new MappingJackson2JsonView();
    defaultView.setExtractValueFromSingleKeyModel(true);

    ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
    contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
    contentViewResolver.setViewResolvers(Arrays.<ViewResolver>asList(viewResolver));
    contentViewResolver.setDefaultViews(Arrays.<View>asList(defaultView));
    return contentViewResolver;
  }