Package org.springframework.http.converter.json

Examples of org.springframework.http.converter.json.MappingJacksonValue


  @Override
  public final Object beforeBodyWrite(Object body, MethodParameter returnType,
      MediaType contentType, Class<? extends HttpMessageConverter<?>> converterType,
      ServerHttpRequest request, ServerHttpResponse response) {

    MappingJacksonValue container = getOrCreateContainer(body);
    beforeBodyWriteInternal(container, contentType, returnType, request, response);
    return container;
  }
View Full Code Here


  /**
   * Wrap the body in a {@link MappingJacksonValue} value container (for providing
   * additional serialization instructions) or simply cast it if already wrapped.
   */
  protected MappingJacksonValue getOrCreateContainer(Object body) {
    return (body instanceof MappingJacksonValue ? (MappingJacksonValue) body : new MappingJacksonValue(body));
  }
View Full Code Here

    if (jsonpParameterValue != null) {
      if (value instanceof MappingJacksonValue) {
        ((MappingJacksonValue) value).setJsonpFunction(jsonpParameterValue);
      }
      else {
        MappingJacksonValue container = new MappingJacksonValue(value);
        container.setJsonpFunction(jsonpParameterValue);
        value = container;
      }
    }
    return value;
  }
View Full Code Here

   */
  protected Object filterAndWrapModel(Map<String, Object> model, HttpServletRequest request) {
    Object value = filterModel(model);
    Class<?> serializationView = (Class<?>) model.get(JsonView.class.getName());
    if (serializationView != null) {
      MappingJacksonValue container = new MappingJacksonValue(value);
      container.setSerializationView(serializationView);
      value = container;
    }
    return value;
  }
View Full Code Here

    writePrefix(generator, object);
    Class<?> serializationView = null;
    Object value = object;

    if (value instanceof MappingJacksonValue) {
      MappingJacksonValue container = (MappingJacksonValue) value;
      value = container.getValue();
      serializationView = container.getSerializationView();
    }
    if (serializationView != null) {
      this.objectMapper.writerWithView(serializationView).writeValue(generator, value);
    }
    else {
View Full Code Here

  @Test
  public void jsonPostForObjectWithJacksonView() throws URISyntaxException {
    HttpHeaders entityHeaders = new HttpHeaders();
    entityHeaders.setContentType(new MediaType("application", "json", Charset.forName("UTF-8")));
    MySampleBean bean = new MySampleBean("with", "with", "without");
    MappingJacksonValue jacksonValue = new MappingJacksonValue(bean);
    jacksonValue.setSerializationView(MyJacksonView1.class);
    HttpEntity<MappingJacksonValue> entity = new HttpEntity<MappingJacksonValue>(jacksonValue, entityHeaders);
    String s = template.postForObject(baseUrl + "/jsonpost", entity, String.class, "post");
    assertTrue(s.contains("\"with1\":\"with\""));
    assertFalse(s.contains("\"with2\":\"with\""));
    assertFalse(s.contains("\"without\":\"without\""));
View Full Code Here

    JacksonViewBean bean = new JacksonViewBean();
    bean.setWithView1("with");
    bean.setWithView2("with");
    bean.setWithoutView("without");

    MappingJacksonValue jacksonValue = new MappingJacksonValue(bean);
    jacksonValue.setSerializationView(MyJacksonView1.class);
    this.writeInternal(jacksonValue, outputMessage);

    String result = outputMessage.getBodyAsString(Charset.forName("UTF-8"));
    assertThat(result, containsString("<withView1>with</withView1>"));
    assertThat(result, not(containsString("<withView2>with</withView2>")));
View Full Code Here

TOP

Related Classes of org.springframework.http.converter.json.MappingJacksonValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.