Search in sources :

Example 6 with MappingJacksonValue

use of org.springframework.http.converter.json.MappingJacksonValue in project spring-framework by spring-projects.

the class MappingJackson2XmlHttpMessageConverterTests method jsonView.

@Test
public void jsonView() throws Exception {
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    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(StandardCharsets.UTF_8);
    assertThat(result, containsString("<withView1>with</withView1>"));
    assertThat(result, not(containsString("<withView2>with</withView2>")));
    assertThat(result, not(containsString("<withoutView>without</withoutView>")));
}
Also used : MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) Test(org.junit.Test)

Aggregations

MappingJacksonValue (org.springframework.http.converter.json.MappingJacksonValue)6 FilterProvider (com.fasterxml.jackson.databind.ser.FilterProvider)2 Test (org.junit.Test)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 MediaType (org.springframework.http.MediaType)1 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)1