コード例 #1
0
  @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;
  }
コード例 #2
0
  @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;
  }
コード例 #3
0
 @Override
 public void setPrefixJson(boolean prefixJson) {
   super.setPrefixJson(prefixJson);
   this.jsonPrefix = "{} && ";
 }
コード例 #4
0
 @Override
 public void setJsonPrefix(String jsonPrefix) {
   super.setJsonPrefix(jsonPrefix);
   this.jsonPrefix = jsonPrefix;
 }
コード例 #5
0
 @Override
 public void setUpdateContentLength(boolean updateContentLength) {
   super.setUpdateContentLength(updateContentLength);
   this.updateContentLength = updateContentLength;
 }
コード例 #6
0
 @Bean
 public View jsonTemplate() {
   MappingJackson2JsonView view = new MappingJackson2JsonView();
   view.setPrettyPrint(true);
   return view;
 }
コード例 #7
0
ファイル: JsonResolver.java プロジェクト: rokerber/aztec
 @Override
 public View resolveViewName(String viewName, Locale locale) throws Exception {
   MappingJackson2JsonView jsonView = new MappingJackson2JsonView();
   jsonView.setPrettyPrint(true);
   return jsonView;
 }