com.fasterxml.jackson.databind.annotation.JsonAppend源码实例Demo

类com.fasterxml.jackson.databind.annotation.JsonAppend源码实例Demo

下面列出了com.fasterxml.jackson.databind.annotation.JsonAppend 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * {@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
    );
}
 
@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));

}
 
源代码评论
动弹
沙发等你来抢
 类方法
 同包方法