Search in sources :

Example 1 with VirtualBeanPropertyWriter

use of com.fasterxml.jackson.databind.ser.VirtualBeanPropertyWriter in project jackson-databind by FasterXML.

the class JacksonAnnotationIntrospector method _constructVirtualProperty.

protected BeanPropertyWriter _constructVirtualProperty(JsonAppend.Prop prop, MapperConfig<?> config, AnnotatedClass ac) {
    PropertyMetadata metadata = prop.required() ? PropertyMetadata.STD_REQUIRED : PropertyMetadata.STD_OPTIONAL;
    PropertyName propName = _propertyName(prop.name(), prop.namespace());
    JavaType type = config.constructType(prop.type());
    // now, then, we need a placeholder for member (no real Field/Method):
    AnnotatedMember member = new VirtualAnnotatedMember(ac, ac.getRawType(), propName.getSimpleName(), type);
    // and with that and property definition
    SimpleBeanPropertyDefinition propDef = SimpleBeanPropertyDefinition.construct(config, member, propName, metadata, prop.include());
    Class<?> implClass = prop.value();
    HandlerInstantiator hi = config.getHandlerInstantiator();
    VirtualBeanPropertyWriter bpw = (hi == null) ? null : hi.virtualPropertyWriterInstance(config, implClass);
    if (bpw == null) {
        bpw = (VirtualBeanPropertyWriter) ClassUtil.createInstance(implClass, config.canOverrideAccessModifiers());
    }
    // one more thing: give it necessary contextual information
    return bpw.withConfig(config, ac, propDef, type);
}
Also used : HandlerInstantiator(com.fasterxml.jackson.databind.cfg.HandlerInstantiator) VirtualBeanPropertyWriter(com.fasterxml.jackson.databind.ser.VirtualBeanPropertyWriter)

Aggregations

HandlerInstantiator (com.fasterxml.jackson.databind.cfg.HandlerInstantiator)1 VirtualBeanPropertyWriter (com.fasterxml.jackson.databind.ser.VirtualBeanPropertyWriter)1