com.fasterxml.jackson.databind.annotation.JsonAppend Java Examples

The following examples show how to use com.fasterxml.jackson.databind.annotation.JsonAppend. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VirtualPropertiesWriter.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public VirtualPropertiesWriter withConfig(MapperConfig<?> config, AnnotatedClass declaringClass, BeanPropertyDefinition propDef, JavaType type) {
    return new VirtualPropertiesWriter(
            propDef,
            new AnnotationCollector.OneAnnotation(
                    declaringClass.getRawType(),
                    declaringClass.getAnnotations().get(JsonAppend.class)
            ),
            type,
            virtualProperties,
            valueResolver,
            filters
    );
}
 
Example #2
Source File: VirtualPropertiesWriterTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void writerCreatedWithDeprecatedConstructorWritesGivenProperties() throws Exception {

    // given
    ObjectMapper objectMapper = new ObjectMapper();
    SerializationConfig config = objectMapper.getSerializationConfig();

    JavaType javaType = config.constructType(LogEvent.class);
    AnnotatedClass annotatedClass = createTestAnnotatedClass(config, javaType);

    SimpleBeanPropertyDefinition simpleBeanPropertyDefinition =
            getTestBeanPropertyDefinition(config, javaType, annotatedClass);

    String expectedName = UUID.randomUUID().toString();
    String expectedValue = UUID.randomUUID().toString();
    VirtualProperty virtualProperty = spy(createNonDynamicVirtualProperty(expectedName, expectedValue));

    ValueResolver valueResolver = createTestValueResolver(virtualProperty, expectedValue);

    VirtualPropertiesWriter writer = new VirtualPropertiesWriter(
            simpleBeanPropertyDefinition,
            new AnnotationCollector.OneAnnotation(
                    annotatedClass.getRawType(),
                    annotatedClass.getAnnotations().get(JsonAppend.class)
            ),
            javaType,
            new VirtualProperty[] { virtualProperty },
            valueResolver
    );

    JsonGenerator jsonGenerator = mock(JsonGenerator.class);

    // when
    writer.serializeAsField(new Object(), jsonGenerator, mock(SerializerProvider.class));

    // then
    verify(jsonGenerator).writeFieldName(eq(expectedName));
    verify(jsonGenerator).writeString(eq(expectedValue));

}