use of com.baeldung.jackson.annotation.extra.AppendBeans.BeanWithAppend in project tutorials by eugenp.
the class ExtraAnnotationUnitTest method whenUsingJsonAppendAnnotation_thenCorrect.
@Test
public void whenUsingJsonAppendAnnotation_thenCorrect() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
BeanWithAppend bean = new BeanWithAppend(2, "Bean With Append Annotation");
ObjectWriter writer = mapper.writerFor(BeanWithAppend.class).withAttribute("version", "1.0");
String jsonString = writer.writeValueAsString(bean);
assertThat(jsonString, containsString("version"));
assertThat(jsonString, containsString("1.0"));
}
Aggregations