Search in sources :

Example 1 with BeanWithoutAppend

use of com.baeldung.jackson.annotation.extra.AppendBeans.BeanWithoutAppend in project tutorials by eugenp.

the class ExtraAnnotationUnitTest method whenNotUsingJsonAppendAnnotation_thenCorrect.

@Test
public void whenNotUsingJsonAppendAnnotation_thenCorrect() throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    BeanWithoutAppend bean = new BeanWithoutAppend(2, "Bean Without Append Annotation");
    ObjectWriter writer = mapper.writerFor(BeanWithoutAppend.class).withAttribute("version", "1.0");
    String jsonString = writer.writeValueAsString(bean);
    assertThat(jsonString, not(containsString("version")));
    assertThat(jsonString, not(containsString("1.0")));
}
Also used : BeanWithoutAppend(com.baeldung.jackson.annotation.extra.AppendBeans.BeanWithoutAppend) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

BeanWithoutAppend (com.baeldung.jackson.annotation.extra.AppendBeans.BeanWithoutAppend)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1